Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
53
rated 0 times [  59] [ 6]  / answers: 1 / hits: 185280  / 11 Years ago, tue, march 19, 2013, 12:00:00

I have this object. I want to iterate this object in JavaScript. How is this possible?



var dictionary = {
data: [
{id:0,name:ABC},
{id:1,name:DEF}
],
images: [
{id:0,name:PQR},
{id:1,name:xyz}
]
};

More From » arrays

 Answers
44

You can do it with the below code. You first get the data array using dictionary.data and assign it to the data variable. After that you can iterate it using a normal for loop. Each row will be a row object in the array.



var data = dictionary.data;

for (var i in data)
{
var id = data[i].id;
var name = data[i].name;
}


You can follow similar approach to iterate the image array.


[#79495] Monday, March 18, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cristinadomoniquel

Total Points: 320
Total Questions: 94
Total Answers: 94

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
cristinadomoniquel questions
Wed, Apr 7, 21, 00:00, 3 Years ago
Tue, Dec 1, 20, 00:00, 4 Years ago
Mon, Nov 23, 20, 00:00, 4 Years ago
Mon, Aug 17, 20, 00:00, 4 Years ago
;