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

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

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

console.log(arr);


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

// 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]);
}

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):

var 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);

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.

var arr = [1, 2, 3];
arr.unshift(0);
console.log(arr);

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.

const 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);

🌐
W3Schools
w3schools.com › jsref › jsref_push.asp
JavaScript Array push() Method
The push() method adds new items to the end of an array.
🌐
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. ... const obj = { length: 0, addElem(elem) { // obj.length is automatically incremented // every time an element is added.
Discussions

How can I add new array elements at the beginning of an array in JavaScript? - Stack Overflow
I have a need to add or prepend elements at the beginning of an array. For example, if my array looks like below: [23, 45, 12, 67] And the response from my AJAX call is 34, I want the updated arra... More on stackoverflow.com
🌐 stackoverflow.com
Can you only add an array to another array?
Push: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push const numbers = [1, 2, 3]; numbers.push(4); console.log(numbers); // [1, 2, 3, 4] const arrays = [[1, 2], [3, 4]]; arrays.push([5, 6]); console.log(arrays); // [[1, 2], [3, 4], [5, 6]] const whatever = [{ name: 'Sue' }, false, null]; whatever.push('eleventy'); console.log(whatever); // [{ name: 'Sue' }, false, null, 'eleventy'] Concat: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat const odds = [1, 3]; const evens = [2, 4]; const all = odds.concat(evens); console.log(odds); // [1, 3] console.log(evens); // [2, 4] console.log(all); // [1, 3, 2, 4] Spread operator: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax const odds = [1, 3]; const evens = [2, 4]; const all = [...odds, ...evens]; console.log(odds); // [1, 3] console.log(evens); // [2, 4] console.log(all); // [1, 3, 2, 4] More on reddit.com
🌐 r/learnjavascript
9
6
October 4, 2022
How to insert an item into an array at a specific index with JavaScript?
Although JavaScript provides various methods to add and remove elements at the beginning or end of an array, inserting an element at a specific index require… More on digitalocean.com
🌐 digitalocean.com
1
April 9, 2023
How do javascript arrays work under the hood?
The answer is that it depends on how you're using the array and what is in the array, and even then, it depends on the JavaScript engine that is executing the code. In V8, for example, if your array only contains integers, it'll be backed by a C++ array of integers. Typically, the backing array will be bigger than the number of integers it currently contains. If it contains a mixture of integers and floating point values or only floating point values, it'll be backed by an array of doubles. If it contains only objects, or a mixture of numbers and objects, it'll backed by an array of pointers. Even though JavaScript itself doesn't have a concept of 'integer' or 'double' - it just sees them all as 'number', V8 keeps track and makes it so arrays are a bit faster and more memory efficient if you only put integers in them. If you call push() when the backing array is full, it'll allocate a new, bigger backing array, copy the existing elements over, and then add the new value you pushed. This is similar to the implementation of ArrayList in Java or vector in C++. All of the above only is only sure to apply if your array is packed, and not sparse - i.e. you don't have any gaps in the array. If you do something like let abc = [1,2,3]; abc[100] = 50; you now have a sparse array. If is not too spare, it'll still be backed by an array, with empty array indices replaced with a 'hole' value. If you look at V8's C++ array source (linked below), you'll see calls to element->is_the_hole(i). If an array is very sparse, it'll no longer be backed by an array in memory. Instead, it will be backed by a dictionary/hashtable, and it'll take longer to both access elements and iterate through the array. If you're interested, you can read through V8's array implementation in C++ here . You'll notice that it often checks the following constants: PACKED_SMI_ELEMENTS - a packed integer array PACKED_DOUBLE_ELEMENTS - a packed double array PACKED_ELEMENTS - a packed object array HOLEY_SMI_ELEMENTS - a sparse integer array HOLEY_DOUBLE_ELEMENTS - a sparse double array HOLEY_ELEMENTS - a sparse object array DICTIONARY_ELEMENTS - a very sparse array that is backed by a dictionary And you'll see that it always tries to do whatever will be fastest for the array it is operating on. Lots of builtin functions like push, pop, shift, unshift, and concat do different things depending on the array's density and what kind of elements it contains. Some other things to keep in mind: if you have an array that only contains integers, and you push a floating point number or other type into it, it will be 'downgraded' for the rest of its life, even if you purge the non integers from it. Also keep in mind that none of these implementation details are guaranteed. A naive implementation of JavaScript's Array object could be backed by a linked list, and it would still work the same way it does now. It would just be slower. Actually, if you grab an early copy of the Mozilla source code from 20 years ago, you'll find that arrays were backed by ordinary JS objects without much optimization, just some extra code to handle special cases like the `length` property. More on reddit.com
🌐 r/javascript
11
18
November 29, 2018
Top answer
1 of 16
5429

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

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

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

console.log(arr);


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

// 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]);
}

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):

var 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);

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.

var arr = [1, 2, 3];
arr.unshift(0);
console.log(arr);

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.

const 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);

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():

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

var ar3 = ar1.concat(ar2);

alert(ar1);
alert(ar2);
alert(ar3);

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

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

ar1 = ar1.concat(ar2);
alert(ar1);

There is a lot of great information on JavaScript Reference.

🌐
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 - When you want to add elements to an array in JavaScript, you can use push() or unshift().
Top answer
1 of 12
4062

Use unshift. It's like push, except it adds elements to the beginning of the array instead of the end.

  • unshift/push - add an element to the beginning/end of an array
  • shift/pop - remove and return the first/last element of an array

A simple diagram...

unshift -> [array] <- push
shift   <- [array] -> pop

and chart:

  add remove start end
push X X
pop X X
unshift X X
shift X X

Check out the MDN Array documentation. Virtually every language that has the ability to push/pop elements from an array will also have the ability to unshift/shift (sometimes called push_front/pop_front) elements, you should never have to implement these yourself.


As pointed out in the comments, if you want to avoid mutating your original array, you can use concat, which concatenates two or more arrays together. You can use this to functionally push a single element onto the front or back of an existing array; to do so, you need to turn the new element into a single element array:

const array = [3, 2, 1]

const newFirstElement = 4

const newArray = [newFirstElement].concat(array) // [ 4, 3, 2, 1 ]

console.log(newArray);

concat can also append items. The arguments to concat can be of any type; they are implicitly wrapped in a single-element array, if they are not already an array:

const array = [3, 2, 1]

const newLastElement = 0

// Both of these lines are equivalent:
const newArray1 = array.concat(newLastElement) // [ 3, 2, 1, 0 ]
const newArray2 = array.concat([newLastElement]) // [ 3, 2, 1, 0 ]

console.log(newArray1);
console.log(newArray2);

2 of 12
1761

var a = [23, 45, 12, 67];
a.unshift(34);
console.log(a); // [34, 23, 45, 12, 67]

🌐
ReqBin
reqbin.com › code › javascript › vpqnwujy › javascript-array-insert-example
How do I insert elements into an array in JavaScript?
December 16, 2022 - The array.push(element1, element2, ...) method in JavaScript is used to add one or more elements to the end of an array.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-add-an-object-to-an-array-in-javascript
JavaScript- Add an Object to JS Array - GeeksforGeeks
It can be used to add, remove, or replace elements in an array. ... let users = [ { name: "Jiya", age: 30 }, { name: "Jolly", age: 25 } ]; let newUser = { name: "Meeta", age: 35 }; users.splice(1, 0, newUser); console.log(users); ... The splice() method inserts the object { name: "Meeta", age: 35 } at index 1, which is between "Jiya" and "Jolly". The second argument is 0, meaning no elements are removed, just the object is added. In JavaScript, we can add objects to arrays using various methods.
Published   July 12, 2025
🌐
freeCodeCamp
freecodecamp.org › news › how-to-insert-an-element-into-an-array-in-javascript
Push into an Array in JavaScript – How to Insert an Element into an Array in JS
November 7, 2024 - If you want to add an element to a particular location of your array, use splice(). And finally, when you want to maintain your original array, you can use the concat() method. In JavaScript, you use the unshift() method to add one or more elements to the beginning of an array and it returns the array's length after the new elements have been added.
🌐
HostingAdvice
hostingadvice.com › home › how-to › javascript "add to array" functions (push vs unshift vs others)
JavaScript "Add to Array" Functions (push vs unshift vs others)
March 25, 2023 - If you need to add an element or multiple elements to the end of an array, the push() method will almost always be your simplest and quickest option.
🌐
W3Schools
w3schools.com › js › js_arrays.asp
JavaScript Arrays
You should use arrays when you want the element names to be numbers. JavaScript has a built-in array constructor new Array().
🌐
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.
🌐
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!

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array
Array - JavaScript | MDN
February 24, 2026 - Adds one or more elements to the front of an array, and returns the new length of the array. ... Returns a new array iterator object that contains the values for each index in the array. ... Returns a new array with the element at the given index replaced with the given value, without modifying the original array. ... An alias for the values() method by default. This section provides some examples of common array operations in JavaScript...
🌐
CoreUI
coreui.io › answers › how-to-add-an-item-to-an-array-in-javascript
How to add an item to an array in JavaScript · CoreUI
September 18, 2025 - Use the push() method to add one or more items to the end of an array. const fruits = ['apple', 'banana'] fruits.push('orange') // Result: ['apple', 'banana', 'orange'] The push() method modifies the original array by adding the specified element ...
🌐
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 - Understanding the internal mechanics helps explain why unshift() has O(n) time complexity. 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
🌐
freeCodeCamp
freecodecamp.org › news › insert-into-javascript-array-at-specific-index
How to Insert into a JavaScript Array at a Specific Index – JS Push
November 7, 2024 - In this code, the splice() method is called on the numbers array, starting at index 2, with a deleteCount of 0. You then add the new element 3 to the array at the start index. The result is the modified array [1, 2, 3, 4, 5]. In this article, you have learned the two major techniques for inserting elements into a JavaScript array at a specific index.
🌐
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.
🌐
Quora
quora.com › What-method-can-you-use-to-add-an-element-to-an-array-in-JavaScript
What method can you use to add an element to an array in JavaScript? - Quora
1. Push 2. unshift 3. splice The push method is used to add elements at the end of the array. The push method returns the new length of the array after inserting the element. [code]var arr=[1]; arr.push(2);...
🌐
DigitalOcean
digitalocean.com › community › questions › how-to-insert-an-item-into-an-array-at-a-specific-index-with-javascript
How to insert an item into an array at a specific index with JavaScript? | DigitalOcean
April 9, 2023 - In this example, we inserted the ‘grape’ element at index 1 in the fruits array. The splice() method offers a simple and efficient way to insert an item into an array at a specific index in JavaScript.