• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 523
  • Last Modified:

JavaScript: Get Key and Value from Object

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
hankknight
Asked:
hankknight
1 Solution
 
s_chilkuryCommented:
for (var key in data) {
        if (data.hasOwnProperty(key)) {
           user[key] = data[key];
        }
    }
0
 
hankknightAuthor Commented:
Thanks.
for (var key in data) {
        if (data.hasOwnProperty(key)) {
            alert('Key:' + key + '\nValue:' + data[key] );
        }
}

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now