#todayilearned

by @jm3 · aka John Manoogian3

Frequent, bite-size mini-milestone updates as I fast-forward merge* my front-end web development skills up to 2019 levels. Learn more

Splice using Array.splice

Posted at — Jun 1, 2019
  • changes array contents in place by removing or replacing existing elements and/or adding new elements

  • remove a range of elements:

    gas.splice(0, 4) // removes first four elements
    

  • splice in new elements at the beginning, middle, or end, replacing the Index → Count range defined by the first two args:

    gas.splice(1, 0, 'foo', 'bar'); // inserts two new els at idx 1