O'Reilly logo
  • Patrick S thinks this is interesting:

Now, let's say we want to insert numbers 2 to 4 back into the array starting from position 5. We can again use the splice method to do this:

numbers.splice(5,0,2,3,4);

The first argument of the method is the index we want to remove or insert elements from. The second argument is the number of elements we want to remove (in this case, we do not want to remove any, so we pass the value 0 (zero)). And the third argument (and onwards) are the values we would like to insert into the array (el...

From

Cover of Learning JavaScript Data Structures and Algorithms

Note

Splice - to insert values