我是javascript的新手程序员。请引导我走正确的道路。
下面是一个大小为2x3x3的三维数组
"items": [ [ [1,2,3], [4,5,6], [7,8,9] ], [ [10,11,12], [13,14,15], [16,17,18] ] ]现在,我需要插入一行,类似于索引1或2 [ [19,20,21], [22,23,24], [25,26,27] ] 的。
我尝试了接合函数,但都失败了。
作为一个多维数组,我不知道剪接函数的itemN参数中有什么值。
items.splice(insertIndex, 0, `????`); 我怎样才能做到呢?谢谢
发布于 2015-10-21 10:55:22
使用连接与deleteCount 0(第二个参数)。当你进入你想要添加的二维数组时。
var items = [ [ [1,2,3], [4,5,6], [7,8,9] ], [ [10,11,12], [13,14,15], [16,17,18] ] ];
var add = [ [19,20,21], [22,23,24], [25,26,27] ];
items.splice(insertIndex, 0, add);这里的工作示例:小提琴
发布于 2015-10-21 10:56:09
发布于 2020-07-16 01:13:17
公认的答案是好的。
我做了一个演示,插入中间行的角度作为参考。
我也为谁而担忧。
textarray = [
[{ text: "Content 1" }, { text: "Content 2" }],
[{ text: "Content 3" }, { text: "Content 4" }]
];
rowindex = 1;
insertmiddle() {
let size = this.textarray[0].length;
this.textarray.splice(this.rowindex, 0,
Array(size).fill({ text: "Content", tag: "Content" }));
}https://stackoverflow.com/questions/33257329
复制相似问题