hi = [ { 0: { symbol: "asdf" , name:"adad"} }]
How will you access symbol property here in JS
console.log(hi[0])
outputs { symbol: "asdf" , name:"adad"}
but
console.log(hi[0].symbol)
throws the error that symbol is undefined
hi = [ { 0: { symbol: "asdf" , name:"adad"} }]
How will you access symbol property here in JS
console.log(hi[0])
outputs { symbol: "asdf" , name:"adad"}
but
console.log(hi[0].symbol)
throws the error that symbol is undefined
hi
is an array. First you need to access the object so hi[0]
will provide the first object. Then access the object using the key which is 0
like below
const hi = [{
0: {
symbol: "asdf",
name: "adad"
}
}];
console.log(hi[0][0].symbol)
Like this?
console.log(hi[0][0].symbol)
hi = [ { 0: { symbol: "asdf" , name:"adad"} }]
hi[0][0].symbol is right.
console.log(hi[0]) => 0: {symbol: "asdf", name: "adad"}
console.log(hi[0][0]) => {symbol: "asdf", name: "adad"}
console.log(hi[0][0].symbol) => "asdf"