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:


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...


Cover of Learning JavaScript Data Structures and Algorithms


Splice - to insert values