Add an item to an array in JavaScript

Today we will show you how to add an item to an array in JavaScript. In this article, we will show you three different ways to add items to the end of an array.

In a previous article, we explained how to add an item at the beginning of an array in JavaScript.

Ways to add an item to an array

  1. Using push() method
  2. Using spread operator
  3. Using concat() method

1. Using unshift() method

The push() method adds one or more elements to the end of an array and returns the new length of the array.

You may like this article: Push, Pop, Shift and Unshift Array Methods in JavaScript

2. Using spread operator

We can achieve the same thing using the Spread Operator.

3. Using concat() method

The concat() method is used to merge two or more arrays. This method does not change the existing arrays but instead returns a new array.

That’s it for today.
Thank you for reading. Happy Coding..!! 🙂

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *