Skip to content

Latest commit

 

History

History
23 lines (19 loc) · 645 Bytes

splice-arrays.md

File metadata and controls

23 lines (19 loc) · 645 Bytes
title tags goal date summary categories
Splice using Array.splice
code
Javascript
Front-End Engineering
2019-06-01
The swiss-army knife of arrays
code
  • changes array contents in place by removing or replacing existing elements and/or adding new elements

  • remove a range of elements: {{< highlight javascript >}} gas.splice(0, 4) // removes first four elements {{< / highlight >}}

  • splice in new elements at the beginning, middle, or end, replacing the Index → Count range defined by the first two args: {{< highlight javascript >}} gas.splice(1, 0, 'foo', 'bar'); // inserts two new els at idx 1 {{< / highlight >}}