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)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay