二维数组为extended(不创建新数组):
let array:number[][] = [
[5, 6],
];
为此,我们还有两个二维数组a1
和a2
:
let a1:number[][] = [[1, 2], [3, 4]];
let a2:number[][] = [[7, 8], [9, 10]];
现在的目标是在array
开头插入a1
,在array
结尾插入a2
:
array.unshift(a1);
array.push(a2);
不允许使用该语法,并出现以下错误:
Argument of type 'number[][]' is not assignable to parameter of type 'number[]'.
Type 'number[]' is not assignable to type 'number'.
预期结果如下:
[
[1, 2],
[3, 4],
[5, 6],
[7, 8],
[9, 10]
];
是否提供了一种插入数组的方法,而无需逐个元素迭代和取消移位/推送?
Please not:个 由于现有数组可能会变得非常大,我希望避免复制(例如,通过连接或类似的方式).