Solved

Looping thru json

Posted on 2014-03-26
2
118 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
javascript 5 42
Basic JavaScript Question 3 37
CONVERT JAVASCRIPT BUTTON TO HYPERLINK TEXT 6 12
Jquery get each value 2 0
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

929 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now