Behseini Behseini - 3 years ago 199
Javascript Question

Not Able to Get Values From JS object

Can you please take a look at this demo and let me know why I am not able to extract values from the object?



var obj = {
webSiteName: 'StackOverFlow',
find: 'anything',
onDays: ['sun', 'mon',
'tue',
'wed',
'thu',
'fri',
'sat',
{
name: "jack",
age: 34
},
{
manyNames: ["Narayan", "Payal", "Suraj"]
},
]
};


console.log(obj.onDays[2]);
console.log(obj.onDays.manyNames[1]);




Answer Source

The manyNames object is at the 8th index of the array, so therefore you need this:

console.log(obj.onDays[8].manyNames[1]);

For jack:

console.log(obj.onDays[7].name);

Or age:

onsole.log(obj.onDays[7].age);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download