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

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

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

var 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.

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);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › push
Array.prototype.push() - JavaScript - MDN Web Docs
July 12, 2026 - 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

javascript - How to append something to an array? - Stack Overflow
The spread operator (...) is to spread out all items from a collection. ... Save this answer. ... Show activity on this post. ... Save this answer. ... Show activity on this post. There are a couple of ways to append an array in JavaScript: 1) The push() method adds one or more elements to ... More on stackoverflow.com
🌐 stackoverflow.com
javascript - How can I insert an item into an array at a specific index? - Stack Overflow
Also there isn't any insert method in JavaScript, but we have a method which is a built-in Array method which does the job for you. It's called splice... Let's see what's splice()... The splice() method changes the contents of an array by removing existing elements and/or adding new elements. ... Let's put back 3 in the arr... ... Let's see what we have done... We use splice again, but this time for the second argument, we pass 0, meaning we don't want to delete any item... More on stackoverflow.com
🌐 stackoverflow.com
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
How do dynamic arrays work in JS?
Most JavaScript engines optimize storage if an Array doesn’t contain holes. For example, V8 uses a relatively complex strategy that optimizes even more if an Array only contains “small integers” or double floats (and no holes): https://v8.dev/blog/elements-kinds Other than that, reallocations sometimes can’t be avoided but unused slots (beyond the length = not holes) can be used to prevent that from happening too often. More on reddit.com
🌐 r/learnjavascript
10
14
May 22, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › add-elements-to-a-javascript-array
How to Add Elements to a JavaScript Array? - GeeksforGeeks
July 23, 2025 - JavaScript · const arr = [ 30, 40, 50 ]; arr.unshift(20); console.log("Updated Array: ", arr); arr.unshift(10, 5); console.log("New Updated Array: ", arr); Output · Updated Array: [ 20, 30, 40, 50 ] New Updated Array: [ 10, 5, 20, 30, 40, 50 ] The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place. Syntax · array.splice( start_index, delete_count, item1, ..., itemN ); JavaScript ·
Top answer
1 of 16
5430

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

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

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

var 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.

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);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

2 of 16
1123

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);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

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);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

There is a lot of great information on JavaScript Reference.

🌐
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...
🌐
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.
🌐
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.
Find elsewhere
🌐
W3docs
w3docs.com › javascript
How To Add New Elements To A JavaScript Array | W3Docs
The push() method is an in-built JavaScript method that is used to add a number, string, object, array, or any value to the Array. You can use the push() function that adds new items to the end of an array and returns the new length.
🌐
Vultr Docs
docs.vultr.com › javascript › examples › insert-item-in-an-array
JavaScript Program to Insert Item in an Array | Vultr Docs
December 17, 2024 - Here, both 'screwdriver' and 'wrench' are added to the array. This flexibility makes push() especially valuable for dynamic array operations. Use unshift() to insert at the start of the array. Call unshift() with the item to be added.
🌐
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?
3 weeks ago - You can also add an item to the end of an array by setting the array element at the index equal to the array’s length: const arr = ["Norway", "Namibia"]; arr[arr.length] = "New Zealand"; console.log(arr); // ["Norway", "Namibia", "New Zealand"] This method modifies the original array. Youtube How Sentry.io saved me from disaster (opens in a new tab) Resources Improve Web Browser Performance - Find the JavaScript code causing slowdowns (opens in a new tab)
🌐
daily.dev
daily.dev › home › blog › webdev › add to list javascript: array manipulation basics
Add to List JavaScript: Array Manipulation Basics | daily.dev
May 25, 2026 - By choosing an index number that isn't used yet, you can put a new item right there. When you want to add elements to an array in JavaScript, you can use push() or unshift().
🌐
Sencha
sencha.com › home › blog › how to add elements to the beginning of a javascript array: complete guide (2026)
Add Elements to Array Start in JavaScript - 2026 Guide
May 11, 2026 - Best for JavaScript developers who need to understand the performance implications of array prepending in production applications. ... unshift() is the simplest method for adding elements to the start of an array, but it mutates the original array and has O(n) time complexity
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript add object to array
How to Add Object to Array in JavaScript | Delft Stack
February 2, 2024 - You can add objects of any data type to an array using the push() function. You can also add multiple values to an array by adding them in the push() function separated by a comma.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-add-an-object-to-an-array-in-javascript
JavaScript- Add an Object to JS Array - GeeksforGeeks
The push() method is used to add one or multiple elements to the end of an array. It returns the new length of the array formed. An object can be inserted by passing the object as a parameter to this method.
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.
🌐
Linux Hint
linuxhint.com › add-elements-into-an-array-in-javascript
Linux Hint – Linux Hint
September 9, 2021 - Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
🌐
Programiz
programiz.com › javascript › examples › insert-item-array
JavaScript Program to Insert Item in an Array
To understand this example, you should have the knowledge of the following JavaScript programming topics: ... // program to insert an item at a specific index into an array function insertElement() { let array = [1, 2, 3, 4, 5]; // index to add to let index = 3; // element that you want to ...
🌐
YouTube
youtube.com › watch
5 Ways to Add Items to Arrays in JavaScript - YouTube
In today's video, we'll take a look at 5 different ways to add items to an array using JavaScript. All of these techniques serve their own unique purpose and...
Published: March 30, 2023
🌐
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 - The splice() method in JavaScript arrays is used to add or remove elements from an array. You can use the splice() method to insert elements at a specific index in an array. ... deleteCount is the number of elements you want to remove from the ...