user984003 user984003 - 1 year ago 165
Javascript Question

Get key value of dictionary

How do I get the value from a javascript dictionary? (I don't even know if it's called a dictionary in javascript)

I get the following object (friends) from the facebook sdk. How do I, for example, loop through the names?

{data: [{id: "xxxxx", name: "Friend name"}, {id: "xxxxx", name: "Friend name"}]}

Answer Source

In JavaScript dictionaries are objects. To access object properties you may use either dot notation or square brackets notation. To iterate an array you may use simple for loop.

var obj = {
        data: [{
            id: "xxxxx",
            name: "Friend name"
        }, {
            id: "xxxxx",
            name: "Friend name"

for (var i = 0, len =; i < len; i++) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download