Массива Буквального с литерал объекта внутри Javascript
var insurance = [
{
id: 'John',
policy: [
{name: 'geico', cost: 400},
{name: 'nationwide', cost: 500},
{name: 'maine', cost: 550},
{name: 'litty', cost: 450}
]
},
{
name: 'Chris',
policy: [
{name: 'emran', cost: 400},
{name: 'kite', cost: 500},
{name: 'tile log', cost: 450},
{name: 'seatle ins', cost: 600},
]
}
];
function loop() {
\t var all;
\t for (var i in insurance){
\t \t all.push(insurance[i].id + " " + insurance[i].policy[i].name + " " + insurance[i].policy[i].cost);
\t }
\t return all;
}
console.log(loop());
Я застрял пытаюсь получить доступ значений из свойств. Ответ должен быть как
John geico 400
John nationwide 500
и продолжать, пока она проходит через каждый идентификатор и каждую политику. Я знаю, как добраться до ответа с помощью
console.log(insurance[0].id + " " + insurance[0].policy[0].name + " " + insurance[0].policy[0].cost);
console.log(insurance[0].id + " " + insurance[0].policy[1].name + " " + insurance[0].policy[1].cost);