According to w3schools the definition of splice is
array.splice(index,howmany,item1,.....,itemX)
Instead of item1,.....,itemX I'd like to hand over an array of values.
I've used the build in method apply to call splice on the Array prototype directly:
var test = ["1", "4"],
args = [1, 0, "2", "3"];
Array.prototype.splice.apply(test, args);
console.log(test); // output: [ '1', '2', '3', '4' ]
No comments:
Post a Comment