写了一个意想不到的 bug,输出结果是[[0, 11], ......]
let array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
let test = [0, 1];
let list = [];
for (let index = 0; index < array.length; index++) {
const element = array[index];
test[1] = element;
list.push(test);
}
console.log(list);
修复方法,简单的拷贝一下
list.push([...test]);