How to iterate the json data in jquery.
[{"id":"856","name":"India"}, {"id":"1035","name":"Chennai"}, {"id":"1048","name":"Delhi"}, {"id":"1113","name":"Lucknow"}, {"id":"1114","name":"Bangalore"}, {"id":"1115","name":"Ahmedabad"}, {"id":"1116","name":"Cochin"}, {"id":"1117","name":"London"}, {"id":"1118","name":"New York"}, {"id":"1119","name":"California"} ]
jQuery code snippet to loop through JSON data properties. You have an array of objects/maps so the outer loop loops through those. The inner loop loops through the properties on each object element.
each() or $. each() Function. This is the simplest way of looping around an array or a JSON array in JavaScript or jQuery.
You can use $.each()
like this:
$.each(data, function(i, obj) { //use obj.id and obj.name here, for example: alert(obj.name); });
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