Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Looping thru json

Posted on 2014-03-26
2
Medium Priority
?
128 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 1000 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 83

Accepted Solution

by:
leakim971 earned 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…
Suggested Courses

926 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