Solved

Looping thru json

Posted on 2014-03-26
2
123 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

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

630 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