Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  7] [ 2]  / answers: 1 / hits: 51012  / 11 Years ago, thu, october 10, 2013, 12:00:00

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}]}

More From » key-value

 Answers
6

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 = obj.data.length; i < len; i++) {
console.log(obj.data[i].name);
}

[#75091] Wednesday, October 9, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ryans

Total Points: 514
Total Questions: 92
Total Answers: 121

Location: Liberia
Member since Fri, Oct 22, 2021
3 Years ago
;