Solved

JavaScript: Get Key and Value from Object

Posted on 2014-01-07
2
352 Views
Last Modified: 2014-01-07
I can get the key from an object.  How can I also get the value?
var data = {"One":1,"Two":2, "Three":3};
for (var key in data) {
 alert('Key:' + key + '\nValue:' + '???' )
}

Open in new window

0
Comment
Question by:hankknight
2 Comments
 
LVL 9

Accepted Solution

by:
s_chilkury earned 500 total points
ID: 39762669
for (var key in data) {
        if (data.hasOwnProperty(key)) {
           user[key] = data[key];
        }
    }
0
 
LVL 16

Author Comment

by:hankknight
ID: 39762705
Thanks.
for (var key in data) {
        if (data.hasOwnProperty(key)) {
            alert('Key:' + key + '\nValue:' + data[key] );
        }
}

Open in new window

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

760 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

17 Experts available now in Live!

Get 1:1 Help Now