Put anything into an array using Array.push().

var a=[], b={};
a.push(b);    
// a[0] === b;

Extra information on Arrays

Add more than one item at a time

var x = ['a'];
x.push('b', 'c');
// x = ['a', 'b', 'c']

Add items to the beginning of an array

var x = ['c', 'd'];
x.unshift('a', 'b');
// x = ['a', 'b', 'c', 'd']

Add the contents of one array to another

var x = ['a', 'b', 'c'];
var y = ['d', 'e', 'f'];
x.push.apply(x, y);
// x = ['a', 'b', 'c', 'd', 'e', 'f']
// y = ['d', 'e', 'f']  (remains unchanged)

Create a new array from the contents of two arrays

var x = ['a', 'b', 'c'];
var y = ['d', 'e', 'f'];
var z = x.concat(y);
// x = ['a', 'b', 'c']  (remains unchanged)
// y = ['d', 'e', 'f']  (remains unchanged)
// z = ['a', 'b', 'c', 'd', 'e', 'f']
Answer from John Strickler on Stack Overflow
๐ŸŒ
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
๐ŸŒ
Programiz
programiz.com โ€บ javascript โ€บ examples โ€บ append-object-array
JavaScript Program to Append an Object to an Array
In the above program, the splice() method is used to add an object to an array. The splice() method adds and/or removes an item. ... The first argument represents the index where you want to insert an item. The second argument represents the number of items to be removed (here, 0). The third ...
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ javascript โ€บ examples โ€บ append-an-object-to-an-array
JavaScript Program to Append an Object to An Array
November 8, 2024 - Appending an object to an array ... requirements like immutability and coding style preferences. Use the push() method for a straightforward, in-place addition. Opt for the spread operator or concat() when you need to preserve ...
๐ŸŒ
SamanthaMing
samanthaming.com โ€บ tidbits โ€บ 87-5-ways-to-append-item-to-array
5 Way to Append Item to Array in JavaScript | SamanthaMing.com
5 ways to add an item to the end of an array. Push, Splice, and Length will mutate the original array. Concat and Spread won't and will return a new array...
๐ŸŒ
Sentry
sentry.io โ€บ sentry answers โ€บ javascript โ€บ how do you append something to an array using javascript?
How do you append something to an array using JavaScript? | Sentry
This method takes in elements to add to the array as arguments, changes the original array, and returns the new length of the array. You can append one or more items to an array using spread syntax:
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
W3docs
w3docs.com โ€บ javascript
How to Append an Item to an Array in JavaScript
In this tutorial, you will find out the solutions that JavaScript offers for appending an item to an array. Imagine you want to append a single item to an array. In this case, the push() method, provided by the array object can help you.
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.

๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Array โ€บ push
Array.prototype.push() - JavaScript | MDN
In case you want the value of this to be the same, but return a new array with elements appended to the end, you can use arr.concat([element0, element1, /* ... ,*/ elementN]) instead. Notice that the elements are wrapped in an extra array โ€” otherwise, if the element is an array itself, it would be spread instead of pushed as a single element due to the behavior of concat().
๐ŸŒ
Reddit
reddit.com โ€บ r/learnjavascript โ€บ three ways to append an item to an array (mutative)
r/learnjavascript on Reddit: Three ways to append an item to an array (Mutative)
September 1, 2022 - In this case, we're adding "Cow" at the end of the array by using myArray.length as our index (which is 2)... ... I'm not familiar with the time complexity of the various solutions but that would be the case in which you wouldn't use push - if possible. If there's a more efficient solution and your working with a large amount of data that requires it. ... They all have the same time complexity. Also, JavaScript arrays are dynamic, so pushing into the array has an amortized time complexity of O(1), aka as cheap as it can realistically be.
๐ŸŒ
Flavio Copes
flaviocopes.com โ€บ how-to-append-item-to-array
How to append an item to an array in JavaScript
May 25, 2018 - To append a multiple item to an array, you can use push() by calling it with multiple arguments: const fruits = ['banana', 'pear', 'apple'] fruits.push('mango', 'melon', 'avocado') You can also use the concat() method you saw before, passing ...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ javascript-append-to-array-a-js-guide-to-the-push-method-2
JavaScript Append to Array: a JS Guide to the Push Method
April 19, 2021 - Sometimes you need to append one or more new values at the end of an array. In this situation the push() method is what you need. The push() method will add one or more arguments at the end of an array in JavaScript: let arr = [0, 1, 2, 3];
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ javascript-add-to-an-array-js-append
JavaScript Add to an Array โ€“ JS Append
October 14, 2022 - The spread syntax as used above copies all the values of both arrays into the myArr array: myArr = [ ...myArr1, ...myArr2]. In this article, we talked about the different methods you can use to add and append elements to a JavaScript array.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ javascript-append-element-in-js-array
JavaScript- Append in Array - GeeksforGeeks
July 11, 2025 - JavaScript splice() Method modifies the content of an array by removing existing elements and/or adding new elements. It allows us to add elements inside the array at specific index.
๐ŸŒ
30 Seconds of Code
30secondsofcode.org โ€บ home โ€บ javascript โ€บ array โ€บ append elements to array
Append elements to a JavaScript array - 30 seconds of code
July 10, 2022 - Array.prototype.splice() is more often used for removing elements from an array, but it can append elements, too. While it also mutates the original array, it can append elements anywhere in the array. Similar to previous methods, it supports adding more than one element at once.
๐ŸŒ
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.
Published ย  July 12, 2025