my_array.concat('foo');

concat doesn't alter the original array.

Answer from benjaminadk on Stack Overflow
🌐
Bacancy Technology
bacancytechnology.com › qanda › javascript › add-new-elements-to-an-array-without-overwriting-the-first-one
Learn How to Add New Elements to an Array Without Overwriting the First One
As shown in the above example, using the spread operator we can append new values in the array without removing old values. Here we can also use the concat method to concat both arrays. let arrayOfObjects = [ { key1: "value1", key2: "value2" ...
🌐
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.
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.

🌐
CodyHouse
codyhouse.co › blog › post › javascript-append-to-array
JavaScript quick tip - append to array with examples | CodyHouse
The push method can be used to append an element at the end of an array. var array = ['first', 'second']; array.push('third'); console.log(array); // ['first', 'second', 'third'] If we want to push an array at the end of another array, we can ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › push
Array.prototype.push() - JavaScript | MDN
It only expects the this value to have a length property and integer-keyed properties. Although strings are also array-like, this method is not suitable to be applied on them, as strings are immutable. The following code creates the sports array containing two elements, then appends two elements to it.
🌐
JavaScript in Plain English
javascript.plainenglish.io › javascript-array-appending-c1d7de13a115
JavaScript—Array Appending. Learn The Best Ways to Append new… | by Ange IT | JavaScript in Plain English
April 23, 2024 - If you want to append elements to an array without modifying the original array, you can use the concat() method. concat() creates… ... New JavaScript and Web Development content every day.
🌐
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...
Find elsewhere
🌐
The Valley of Code
thevalleyofcode.com › js-arrays › 7-modifying-an-existing-array-without-mutating-it
Arrays: Modifying an existing array without mutating it
The best way to add an item to the array without mutating its content, in other words creating a new array, is to use the spread operator.
🌐
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];
🌐
GitHub
github.com › learn-co-curriculum › javascript-arrays-lab › issues › 9
Append and return new array without modifying the old one. JavaScript · Issue #9 · learn-co-curriculum/javascript-arrays-lab
I need to append an element to an array and return the new one, leaving the old one unchanged. var kittens = ["Milo", "Otis", "Cat"] function appendKitten(name) { kittens.slice(0); kittens.push(); var clone = kittens.slice(0); return clo...
🌐
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 - The spread operator is supported ... 11), transpilation with Babel is required. The concat() method merges two or more arrays into a new array without modifying the original arrays....
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-extend-an-existing-array-with-another-array-without-creating-a-new-array-in-javascript
Extend existing JS array with Another Array | GeeksforGeeks
November 15, 2024 - To extend an array with another without creating a new array we can use the JavaScript array.push() method. This method extend the array by adding the elements at the end.
🌐
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 - Combine lists: concat() merges ... new one, without altering the original arrays. Direct placement: Use array index notation to add items at specific positions by directly setting them. These methods provide the flexibility to modify arrays directly or create new ones, catering to various scenarios and needs. By mastering these basic operations, you'll be well-equipped to organize and manipulate data in JavaScript...
🌐
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 - You can read more on Slice vs. Splice in JavaScript and when to use them in this detailed article. We can use the concat() method to add elements to an array without mutating or altering the original array.
🌐
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 - concat() provides another way to combine arrays or values without modifying the original data structures. It's a bit more traditional and very effective, especially when dealing with immutability.
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript append array to another
How to Append Array to Another in JavaScript | Delft Stack
March 11, 2025 - Can I use push() to append an array to another array without modifying the original? No, push() modifies the original array.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-append-array-at-the-end-of-another-array
JavaScript - Append Array At The End Of Another Array - GeeksforGeeks
July 23, 2025 - for Loop: Suitable when you need custom logic or condition checks during appending. reduce() Method: A more functional approach but may be less readable for simple tasks. splice() Method: Use when you want to modify the original array in-place without creating a new one. Array.from() Method: Provides a flexible way to create a new array when working with different iterable sources. Comment · Article Tags: Article Tags: JavaScript ·