Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to iterate json data in jquery

Tags:

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"} ] 
like image 445
Elankeeran Avatar asked Nov 20 '10 15:11

Elankeeran


People also ask

How to Loop JSON object in jQuery?

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.

How to Loop JSON array in jQuery?

each() or $. each() Function. This is the simplest way of looping around an array or a JSON array in JavaScript or jQuery.


1 Answers

You can use $.each() like this:

$.each(data, function(i, obj) {   //use obj.id and obj.name here, for example:   alert(obj.name); }); 
like image 103
Nick Craver Avatar answered Sep 23 '22 05:09

Nick Craver