DEV Community

Carlos Alberto
Carlos Alberto

Posted on

how to add items to an array in JS

To add elements to an array we will to use the splice function.

.splice(index, howmany, item1, ....., itemX)

index : what position to add/remove items, Use negative values to specify the position from the end of the array
howmany : items to be removed. If set to 0, no items will be removed
item1, ..., itemX Optional. The new item(s) to be added to the array

Top comments (0)