You can use the apply method of Array.prototype.push():

var a = [1, 2, 3];
var b = ['foo', 'bar'];
Array.prototype.push.apply(a, b);
console.log(a); // Array [ 1, 2, 3, "foo", "bar" ]

or alternatively:

a.push.apply(a, b);
[].push.apply(a, b);

If you're using ES6, it's better to call .push() using the spread operator ... instead. This is more similar to Collection.addAll(...) because you can add values from any iterable object, not just arrays. It also allows you to add multiple iterables at once.

const a = [1, 2, 3];
const b = ['foo', 'bar'];
const c = new Set(['x', 'x', 'y', 'x']);
a.push(...b, ...c);
console.log(a); // Array [ 1, 2, 3, "foo", "bar", "x", "y" ]
Answer from madox2 on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › push
Array.prototype.push() - JavaScript | MDN
Instead, we store the collection on the object itself and use call on Array.prototype.push to trick the method into thinking we are dealing with an array—and it just works, thanks to the way JavaScript allows us to establish the execution context in any way we want. js · const obj = { length: 0, addElem(elem) { // obj.length is automatically incremented // every time an element is added.
People also ask

What is the fastest way to add an element to the beginning of a JavaScript array?
For arrays with fewer than 10,000 elements, unshift() provides the fastest performance when mutation is acceptable. For immutable operations, the spread operator offers the best combination of performance and readability. For very large arrays (100,000+ elements), consider using concat() or building a new array with a loop.
🌐
sencha.com
sencha.com › home › blog › how to add elements to the beginning of an array in javascript (2026 guide)
How to Add Elements to the Beginning of an Array in JavaScript ...
Does unshift() modify the original array?
Yes, unshift() modifies the original array in place. It adds elements to the beginning and shifts existing elements to higher indices. If you need to preserve the original array, use the spread operator or concat() to create a new array instead.
🌐
sencha.com
sencha.com › home › blog › how to add elements to the beginning of an array in javascript (2026 guide)
How to Add Elements to the Beginning of an Array in JavaScript ...
What is the difference between push() and unshift()?
push() adds elements to the end of an array, while unshift() adds elements to the beginning. Both methods mutate the original array and return the new length.
🌐
sencha.com
sencha.com › home › blog › how to add elements to the beginning of an array in javascript (2026 guide)
How to Add Elements to the Beginning of an Array in JavaScript ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › concat
Array.prototype.concat() - JavaScript | MDN
Then, for each argument, its value will be concatenated into the array — for normal objects or primitives, the argument itself will become an element of the final array; for arrays or array-like objects with the property Symbol.isConcatSpreadable set to a truthy value, each element of the argument will be independently added to the final array.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-add-numbers-in-javascript-arrays
JS Sum of an Array – How to Add the Numbers in a JavaScript Array
March 31, 2023 - Next, I used the for loop to iterate over all the elements until the end of the myNums array. I also reassigned the value of the sum variable using the addition assignment operator by adding its current value and the current array element. To learn more about the for loop in JavaScript, give this ...
🌐
Reddit
reddit.com › r/learnjavascript › can you only add an array to another array?
r/learnjavascript on Reddit: Can you only add an array to another array?
October 4, 2022 -

Hi there!

I'm new to JavaScript and was learning about arrays today and saw that the instructor only added an array to another array. Is it possible to add something that is not an array into an array? Iyes, how can I do that?

Thanks in advance!

🌐
W3Schools
w3schools.com › jsref › jsref_push.asp
JavaScript Array push() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST ... Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean
🌐
daily.dev
daily.dev › home › blog › get into tech › add to list javascript: array manipulation basics
Add to List JavaScript: Array Manipulation Basics
December 22, 2025 - Add to the end: Use push() to add one or more items to the end of an array. Add to the beginning: Use unshift() to insert items at the start. Insert anywhere: splice() allows you to add or remove items from any position.
Find elsewhere
🌐
Medium
habtesoft.medium.com › add-elements-to-an-array-in-javascript-a9cc6cd9469f
Add elements to an array in JavaScript | by habtesoft | Medium
October 18, 2024 - One of the simplest ways to add an element to an array in JavaScript is to use the push() method.
🌐
Sencha
sencha.com › home › blog › how to add elements to the beginning of an array in javascript (2026 guide)
How to Add Elements to the Beginning of an Array in JavaScript (2026 Guide)
March 14, 2024 - When you call unshift(), the JavaScript engine executes these steps: Calculate new length: Determine how many elements to add and compute the resulting array size ... This shifting operation explains why unshift() becomes slower as array size increases. For an array with 10,000 elements, adding one element at the beginning requires moving all 10,000 existing elements.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Arrays
Move all elements to the left, renumber them from the index 1 to 0, from 2 to 1 and so on. Update the length property. The more elements in the array, the more time to move them, more in-memory operations. The similar thing happens with unshift: to add an element to the beginning of the array, we need first to move existing elements to the right, increasing their indexes.
Top answer
1 of 16
5428

Use the Array.prototype.push method to append values to the end of an array:

Copy// initialize array
var arr = [
  "Hi",
  "Hello",
  "Bonjour"
];

// append new value to the array
arr.push("Hola");

console.log(arr);
Run code snippetEdit code snippet Hide Results Copy to answer Expand


You can use the push() function to append more than one value to an array in a single call:

Copy// initialize array
var arr = ["Hi", "Hello", "Bonjour", "Hola"];

// append multiple values to the array
arr.push("Salut", "Hey");

// display all values
for (var i = 0; i < arr.length; i++) {
  console.log(arr[i]);
}
Run code snippetEdit code snippet Hide Results Copy to answer Expand

Note that the push() method returns the updated length of the array.


Update

If you want to add the items of one array to another array, you can use firstArray.concat(secondArray):

Copyvar arr = [
  "apple",
  "banana",
  "cherry"
];

// Do not forget to assign the result as, unlike push, concat does not change the existing array
arr = arr.concat([
  "dragonfruit",
  "elderberry",
  "fig"
]);

console.log(arr);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

Update

Just an addition to this answer if you want to prepend any value to the start of an array (i.e. first index) then you can use Array.prototype.unshift for this purpose.

Copyvar arr = [1, 2, 3];
arr.unshift(0);
console.log(arr);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

It also supports appending multiple values at once just like push.


Update

Another way with ES6 syntax is to return a new array with the spread syntax. This leaves the original array unchanged, but returns a new array with new items appended or prepended, compliant with the spirit of functional programming.

Copyconst arr1 = [
  "Hi",
  "Hello",
  "Bonjour",
];
const arr2 = [
  "Ciao",
  "Hej",
  "Merhaba",
];

const newArr1 = [
  ...arr1,
  "Salut",
];
const newArr2 = [
  "Salut",
  ...arr2,
];
const newArr3 = [
  ...arr1,
  ...arr2,
];

console.log(newArr1, newArr2, newArr3);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

2 of 16
1122

If you're only appending a single variable, then push() works just fine. If you need to append another array, use concat():

Copyvar ar1 = [1, 2, 3];
var ar2 = [4, 5, 6];

var ar3 = ar1.concat(ar2);

alert(ar1);
alert(ar2);
alert(ar3);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

The concat does not affect ar1 and ar2 unless reassigned, for example:

Copyvar ar1 = [1, 2, 3];
var ar2 = [4, 5, 6];

ar1 = ar1.concat(ar2);
alert(ar1);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

There is a lot of great information on JavaScript Reference.

🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-add-an-object-to-an-array-in-javascript
JavaScript- Add an Object to JS Array - GeeksforGeeks
The unshift() method is used to add one beginning of an array. It returns the length of the new array formed. An object can be inserted by passing the object as a parameter to this method. ... let list = ["GFG", "Contribute", "Explore"]; let obj = { name: "GFG User", age: 30 }; list.unshift(obj); console.log(list); ... This approach involves using the concat method, which combines two arrays non-destructively. It returns a new array containing all elements from the original arrays without modifying them.
Published   July 12, 2025
🌐
CodyHouse
codyhouse.co › blog › post › javascript-append-to-array
JavaScript quick tip - append to array with examples | CodyHouse
The unshift method, like the push method, can be used to combine arrays. The difference is that the unshift method adds at the beginning of the array, rather than the end.
🌐
freeCodeCamp
freecodecamp.org › news › javascript-array-insert-how-to-add-to-an-array-with-the-push-unshift-and-concat-functions
JavaScript Array Insert - How to Add to an Array with the Push, Unshift, and Concat Functions
August 25, 2020 - There are multiple different ways to properly do a "deep clone" of an array, but I will leave that for you as homework. When you want to add an element to the end of your array, use push(). If you need to add an element to the beginning of your ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array
Array - JavaScript | MDN
Joins all elements of an array into a string. ... Returns a new array iterator that contains the keys for each index in the calling array. ... Returns the last (greatest) index at which a given element can be found in the calling array, or -1 if none is found. ... Returns a new array containing the results of invoking a function on every element in the calling array. ... Removes the last element from an array and returns that element. ... Adds one or more elements to the end of an array, and returns the new length of the array.
🌐
HostingAdvice
hostingadvice.com › home › how-to
JavaScript "Add to Array" Functions (push vs unshift vs others)
March 25, 2023 - The concat() method returns a new combined array comprised of the array on which it is called, joined with the array (or arrays) from its argument. To add some elements to another array using concat() do the following:
🌐
ServiceNow
support.servicenow.com › kb
Adding new values to an array using Array.push() replaces all values in the array with the last value pushed - Support and Troubleshooting - Now Support Portal
August 24, 2024 - When adding new values to an array object using Array.push(), it replaces all values in the array object with the last value pushed. Consider the following sample script to fetch all the open P1 incidents
🌐
Stack Abuse
stackabuse.com › bytes › push-an-object-to-an-array-in-javascript
Push an Object to an Array in JavaScript
July 23, 2022 - To add multiple objects to an array, you can pass multiple objects as arguments to the push() method, which will add all of the items to the end of the array.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › splice
Array.prototype.splice() - JavaScript | MDN
If start >= array.length, no element will be deleted, but the method will behave as an adding function, adding as many elements as provided. If start is omitted (and splice() is called with no arguments), nothing is deleted. This is different from passing undefined, which is converted to 0. ... An integer indicating the number of elements in the array to remove from start. If deleteCount is omitted, or if its value is greater than or equal to the number of elements after the position specified by start, then all the elements from start to the end of the array will be deleted.
🌐
Programiz
programiz.com › javascript › examples › append-object-array
JavaScript Program to Append an Object to an Array
To understand this example, you should have the knowledge of the following JavaScript programming topics: ... // program to append an object to an array function insertObject(arr, obj) { // append object arr.push(obj); console.log(arr); } // original array let array = [1, 2, 3]; // object to ...