Should be quite a common answer but I haven't found it.
Using client-side javascript:
My client receives some JSON string:
response =
[
{"id1":"value1" , "time1":"valuetime1"},
{"id2":"value2" , "time2":"valuetime2"}
]
I understand that I can simply parse the JSON string with this command:
response = JSON.parse(response);
But what is the next command to access each of the objects individually? I would prefer to not use jQuery.
In plain JavaScript, just use a simple for loop:
for(var i = 0; i < response.length; i++){
console.log(response[i]); // Object with id and time
}
-or-
response.forEach(function(object){
console.log(object);
});
Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With