假设我有一本字典
h = { toys: [ { name: 'Toy 1', price: 900 } ] }
还有一个数组
arr = []
如何用h扩展arr
arr.push(h)
等于[ { toys: [ [Object] ] } ]
期望的结果是:
[ { toys: [ { name: 'Toy 1', price: 900 } ] } ]
假设我有一本字典
h = { toys: [ { name: 'Toy 1', price: 900 } ] }
还有一个数组
arr = []
如何用h扩展arr
arr.push(h)
等于[ { toys: [ [Object] ] } ]
期望的结果是:
[ { toys: [ { name: 'Toy 1', price: 900 } ] } ]
arr.push(h)给出[{toys:[[Object]]}]
这是因为console.log
某处没有显示嵌套对象的深层次.你只需要使用console.dir
和depth
选项.看看这个:
h = { toys: [{ name: 'Toy 1', price: 900 }] };
arr = [];
arr.push(h);
console.dir(arr, { depth: null });