例如我有一个块数组,这个数组有单个块的大小。
let example = [3,3]; // Chunks array
let auxarrayindex = [1,2,3,4,5,6]; // Array that I want to splice
let example2 = [3,2,3]; // Chunks array
let auxarrayindex2 = [1,2,3,4,5,6,7,8]; // Array that I want to splice
Run Code Online (Sandbox Code Playgroud)
我想要的结果是:
[1,2,3],[4,5,6] and the second [1,2,3],[4,5],[6,7,8]
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
for (let auxexample = 0; auxexample < example.length; auxexample++) {
finalauxarray.push(auxarrayindex.slice(0, example[auxexample]));
}
Run Code Online (Sandbox Code Playgroud)
我的代码的结果是:
[1,2,3],[1,2,3] and the second [1,2,3],[1,2],[1,2,3]
Run Code Online (Sandbox Code Playgroud)