Solved

Looping thru json

Posted on 2014-03-26
2
120 Views
Last Modified: 2014-04-07
In JavaScript how would you loop thru this json structure and output the values of dbname and target.

var object = {
db1 : {dbname : 'xxxxxx',target : '100.0'},
db2 : {dbname : 'yyyyyyy',target : '200.0'},
db3 : {dbname : 'zzzzzz',target : '500.0'}
}

Open in new window

0
Comment
Question by:stargateatlantis
2 Comments
 
LVL 5

Assisted Solution

by:jayakrishnabh
jayakrishnabh earned 250 total points
ID: 39956476
function abc(){
var object = {
db1 : {dbname : 'xxxxxx',target : '100.0'},
db2 : {dbname : 'yyyyyyy',target : '200.0'},
db3 : {dbname : 'zzzzzz',target : '500.0'}
};

$.each(object, function (j, item) {
                alert(object[j].dbname);
                alert(object[j].target);
            });
}
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 250 total points
ID: 39956544
Test page : http://jsfiddle.net/EJPP3/

var object = {
    db1 : {dbname : 'xxxxxx',target : '100.0'},
    db2 : {dbname : 'yyyyyyy',target : '200.0'},
    db3 : {dbname : 'zzzzzz',target : '500.0'}
}

for(var k in object) {
    var dbname = object[k].dbname;
    var target = object[k].target;
    //console.log(dbname + " / " + target);
    alert(dbname + " / " + target);
}

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question