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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay