Answer the question
In order to leave comments, you need to log in
How to iterate over an object in node.js?
3223: {
count: 112,
popular: true,
price: 2,
id: 1,
service: "Facebook",
slug: "3223",
image: "/assets/images/serv/3223.png"
},
vkcom: {
count: 0,
popular: true,
price: 23,
id: 0,
service: "Вконтакте",
slug: "VKcom",
image: "/assets/images/serv/vkcom.png"
},
mailru: {
count: 540,
popular: true,
price: 2,
id: 2,
service: "MailRu",
slug: "MailRu",
image: "/assets/images/serv/mailru.png"
},
Answer the question
In order to leave comments, you need to log in
See Objects: iterating over properties
for (key in obj) {
/* ... делать что-то с obj[key] ... */
}
var obj = {
3223: {
count: 112,
popular: true,
price: 2,
id: 1,
service: "Facebook",
slug: "3223",
image: "/assets/images/serv/3223.png"
},
vkcom: {
count: 0,
popular: true,
price: 23,
id: 0,
service: "Вконтакте",
slug: "VKcom",
image: "/assets/images/serv/vkcom.png"
},
mailru: {
count: 540,
popular: true,
price: 2,
id: 2,
service: "MailRu",
slug: "MailRu",
image: "/assets/images/serv/mailru.png"
}
}
console.log(obj[3223]["count"])
for (key in obj) {
console.log("Для key="+key+" count="+obj[key]["count"])
}
Object.keys(obj).forEach(function(key) {
console.log(key, ':', this[key]["count"]);
}, obj);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question