Friday, 23 August 2013

.each() function showing first object 3 times, instead of all 3 objects

.each() function showing first object 3 times, instead of all 3 objects

A query of my WordPress custom fields, generates this array:
Array ( [genre] => Rock [concert_city] => New York [concert_date] =>
01-16-2014 [start_time] => 8:00 PM ) Array ( [genre] => Jazz
[concert_city] => Chicago [concert_date] => 12-12-2013 [start_time] =>
7:00 PM ) Array ( [genre] => Pop [concert_city] => Los Angeles
[concert_date] => 11-16-2013 [start_time] => 8:00 PM )
This array is stored in:
$array = array();
Need to get this data into jQuery.
$(document).ready(function() {
var event = <?php echo json_encode($array) ?>;
$.each(event,function( index, value ){
console.log(event);
});
});
This only shows me the first object 3 times, instead of all 3 objects. How
can I iterate across all three objects?
And then I need to change them from index:value, into value(concert_date)
: value(concert_city), but right now I'm stuck getting only the first
object in my array 3 times, instead of 3 objects.

No comments:

Post a Comment