crabkilla,
var albumInfoObj = {
"title": "Ray of Light",
"singer": "Madonna",
"year": 1998,
"songs": ["Swim", "Little Star", "Frozen", "Skin", "The Power of Good-Bye"],
"recorded": {
"studioName": "Larrabee North Studio",
"months": 4.5
},
"singles": [{
"name": "Frozen",
"year": 1998
}, {
"name": "Nothing Really Matters",
"year": 1999
}, {
"name": "Ray of Light",
"year": 1998
}],
}
var propList = [];
for (var prop in albumInfoObj.singles[0]) {
propList.push(prop);
}
console.log(propList.join("\n"));
Сообщение от crabkilla
|
Требуется написать цикл for in,
|
Можно обойтись статичным методом Object.keys
var albumInfoObj = {
"title": "Ray of Light",
"singer": "Madonna",
"year": 1998,
"songs": ["Swim", "Little Star", "Frozen", "Skin", "The Power of Good-Bye"],
"recorded": {
"studioName": "Larrabee North Studio",
"months": 4.5
},
"singles": [{
"name": "Frozen",
"year": 1998
}, {
"name": "Nothing Really Matters",
"year": 1999
}, {
"name": "Ray of Light",
"year": 1998
}],
}
console.log(Object.keys(albumInfoObj.singles[0]).join("\n"));