Introduction:
Here I will explain how to iterate through jQuery
string / object using jQuery
or loop through jQuery string / object using jQuery.
Description:
In previous articles I explained jQuery Hover dropdown menu with css, jQuery show modal popup window on pageload, jQuery open videos in modal popup window, jQuery Show gridview row
details on mouseover, jQuery Draggable & Resizable div with example and many
articles relating to JQuery,
JavaScript, asp.net,
code snippets. Now I will explain how to iterate through jQuery
string / object using jQuery
or loop through jQuery string / object using jQuery.
Code
to iterate through JSON object
To iterate through JSON object or string we need to
write the code like as shown below
var str = { "UserDetails":
[{ "Name": "Suresh", "Location":
"Chennai" }, { "Name": "Rohini",
"Location": "Guntur" }, { "Name":
"Mahesh", "Location": "Nuzividu"
}, { "Name": "Madhav", "Location":
"NAGPUR" }, { "Name": "Nagaraju",
"Location": "Hyderabad" }, { "Name": "Kapil",
"Location": "Malaysia" }] };
$(str.UserDetails).each(function(i, e) {
alert(e.Name);
});
|
If you want to see it in
complete example check below code
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<title>jQuery Loop Through JSON Object</title>
<script type="text/javascript">
$(function()
{
var str = { "UserDetails":
[{ "Name": "Suresh", "Location":
"Chennai" }, { "Name": "Rohini",
"Location": "Guntur" }, { "Name":
"Mahesh", "Location": "Nuzividu"
}, { "Name": "Madhav", "Location":
"NAGPUR" }, { "Name": "Nagaraju",
"Location": "Hyderabad" }, { "Name": "Kapil",
"Location": "Malaysia" }] };
$(str.UserDetails).each(function(i, e) {
alert(e.Name);
});
})
</script>
</head>
<body>
<div>
</div>
</body>
</html>
|
Live
Demo
For live demo click on below button to see the above
string values
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
1 comments :
good one
Note: Only a member of this blog may post a comment.