The splice syntax is:
array.splice(start, deleteCount[, item1[, item2[, ...]]]) I have an array of item1, item2, .... How do I insert it into this function?
ADDED: That is, something like this: array.splice(1, 1, ["a","b"])
The splice syntax is:
array.splice(start, deleteCount[, item1[, item2[, ...]]]) I have an array of item1, item2, .... How do I insert it into this function?
ADDED: That is, something like this: array.splice(1, 1, ["a","b"])
A spread operator has been added to ES2015, it allows you to expand an array into an argument list
var array = [1, 2, 3]; array.splice(1, 1, ...["a", "b"]) console.log(array); Previously would have to use the apply method
var array = [1, 2, 3]; array.splice.apply(array, [1, 1].concat(["a", "b"])); // если все известно заранее можно сразу составить нужный массив [1,1,"a","b"] console.log(array); Source: https://ru.stackoverflow.com/questions/611561/
All Articles