该对象怎么了?
const ob= {
"1": [
{
"name": "destination"
}
]
}, {
"2": [
{
"name": "destination"
}
]
}
为什么我不能做ob['1']
或ob['2']
?对象的值不能包含数组?
答案 0 :(得分:2)
您的对象结构不正确。您需要将1
和2
放在对象ob
的同一级别上:
const ob = {
"1": [{
"name": "destination"
}],
"2": [{
"name": "destination"
}]
};
console.log(ob['1']);
console.log(ob['2']);
答案 1 :(得分:1)
对象的结构无效。右括号弄乱了。
const ob = {
"1": [{
"name": "destination",
}],
"2": [{
"name": "destination",
}]
}
console.log(ob['1']);
console.log(ob['2']);