let arr = new Array(3).fill(new Array(4).fill(0));
console.log(arr);
console.log(arr[0] === arr[1]);
[ [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ] ]
true
地址指向相同
let arr1 = new Array(3).fill().map(() => new Array(4).fill(0));
console.log(arr1);
console.log(arr1[0] === arr1[1]);
[ [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ] ]
false
地址指向不同
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)