在你的脚本中,下面的修改怎么样?
发件人:
let newNumbers = numbers.map(function (row) {
return [row.slice(2, 0, "Hello")]
})
let newNumbers = numbers.map(function (row) {
row.splice(2, 0, "Hello");
return row;
});
或者,在这种情况下,可以使用以下修改。
let newNumbers = numbers.map(([a, b, ...c]) => [a, b, "Hello", ...c]);
测试:
let numbers = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
// Attempted outcome = [[1, 2, "Hello", 3], [4, 5, "Hello", 6], [7, 8, "Hello", 9]]
let newNumbers = numbers.map(function (row) {
row.splice(2, 0, "Hello");
return row;
});
console.log(newNumbers);
参考: