Home » Push Multiple Elements in Array JavaScript: 3 Ways

Push Multiple Elements in Array JavaScript: 3 Ways

How to Push Multiple Elements in Array JavaScript 3 Ways

In JavaScript, arrays are a powerful data structure that allows you to store and manipulate multiple elements. Adding new elements is one of the most common operations on arrays, and several ways exist. You’ll find how to push multiple elements into an array in JavaScript. Here are various methods, such as the push method, spread operator, and concat method.

Push Method

The push method is a built-in function in JavaScript. It allows you to add one or more elements to the end of an array. To push multiple elements, into the array in JavaScript you can pass them as separate arguments to the push method. For example:

Here, we created an array arr with three elements, and then pushed three more elements (4, 5, and 6) using the push method. The console log confirms that the new elements have been added to the end of the array.

Spread Operator

Another way to add multiple elements to an array is by using the spread operator. The spread operator is denoted by three dots (...) and can be used to expand an array into its elements. To push multiple pieces using the spread operator, you can create a new array with the elements you want to add. Then use the spread operator to concatenate it with the existing array. For example:

Here, we first created an array arr with three elements, and then created a new array newElements with the elements we want to add. We then used the spread operator to concatenate the two arrays into a new array, and assigned it back to arr. The console log confirms that the new elements have been added to the end of the array.

Concat Method

The concat method is another built-in function in JavaScript. It allows you to combine two or more arrays into a new array. You can create a new array with the elements you want to add. Then use the concat method to merge it with the existing array. For example:

Here, we first created an array arr with three elements, and then created a new array newElements with the elements we want to add. We then used the concat method to merge the two arrays into a new array, and assigned it back to arr. The console log confirms that the new elements have been added to the end of the array.


Each method has its advantages and disadvantages, and you can choose the one that suits your needs best. As a newbie in developing, it’s essential to experiment with different methods and see how they work for you.

Ilyas Ozkurt

Hello I'm İlyas Özkurt. I am a software developer who has been working on websites for 10 years. My first studies in this field were during my high school years. Now I work as a software developer at 6harf and am responsible for all web projects there.

Add comment