The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place.
let a = [1,2,3];
a.splice(0,1); // a = [2,3] return 1
a.splice(0,0,4); // a = [4,2,3] return null
a.splice(1,1,5); // a = [4,5,3] return 2
a.splice(1,2,6); // a = [4,6] return [5,3]
More info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
0 Comments