Reputation: 4564
this is my code, data grabs a json response from ajax. when I do console.debug ...if you click on it to expand this is what it shows:
181818
0.10926253687316
303030
0.054454277286136
d8a890
0.091268436578171
d8d8d8
0.22377581120944
f0d8c0
0.3269616519174
and this my code:
data = $.parseJSON(JSON.stringify(a));
console.debug("Here is blah: %o", data);
var myArray = data;
alert(myArray);
for (var i=0, tot=myArray.length; i < tot; i++) {
console.log(myArray[i]); //"aa", "bb"
}
I am trying to loop through the array and log the pair to the console something like : 181818 = 0.1092 etc..any ideas/suggestions please?
Upvotes: 0
Views: 51
Reputation: 2673
Something like
for (var key in data) {
console.log(key+" = "+data[key]);
}
Remember that data is an object not an array. So in your php code you can just output an array like this
echo json_encode($someArray);
Where
$someArray[181818] = 0.10926253687316;
and so on. Next you can modify as it according to your needs.
Upvotes: 3