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:

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

🌐
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.
🌐
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 ...
🌐
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...
🌐
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.
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];
🌐
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....
🌐
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...
🌐
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...
🌐
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.
🌐
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!

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