When replacing an array in splice (index,n,data), what do you do if the replacement data is an array?

one of the recent problems encountered by the project is

splice(index,n,data)

will become an array to directly replace the selected data. Does Daniel know how to split the array replaced by the index position ? (there are other ways to implement it.)

Jan.29,2022

let list = [1, 2, 3, 7, 8];
list.splice(3, 1, ...[4, 5, 6, 7]);
console.log(list);

ES6

var list = [1, 2, 3, 7, 8];
list.splice.apply(list, [3, 1].concat([4, 5, 6, 7]));
console.log(list);

ES5


splice (index,n,.data)


splice (index,n,data) this statement itself is an array that replaces the index position and separates it separately. Your needs have been met.


ES6 array flattening
let list= [];
list=list.flat (Infinity);

Menu