If you want to modify the original array instead of returning a new array, use .push()...

array1.push.apply(array1, array2);
array1.push.apply(array1, array3);

I used .apply to push the individual members of arrays 2 and 3 at once.

or...

array1.push.apply(array1, array2.concat(array3));

To deal with large arrays, you can do this in batches.

for (var n = 0, to_add = array2.concat(array3); n < to_add.length; n+=300) {
    array1.push.apply(array1, to_add.slice(n, n+300));
}

If you do this a lot, create a method or function to handle it.

var push_apply = Function.apply.bind([].push);
var slice_call = Function.call.bind([].slice);

Object.defineProperty(Array.prototype, "pushArrayMembers", {
    value: function() {
        for (var i = 0; i < arguments.length; i++) {
            var to_add = arguments[i];
            for (var n = 0; n < to_add.length; n+=300) {
                push_apply(this, slice_call(to_add, n, n+300));
            }
        }
    }
});

and use it like this:

array1.pushArrayMembers(array2, array3);

var push_apply = Function.apply.bind([].push);
var slice_call = Function.call.bind([].slice);

Object.defineProperty(Array.prototype, "pushArrayMembers", {
    value: function() {
        for (var i = 0; i < arguments.length; i++) {
            var to_add = arguments[i];
            for (var n = 0; n < to_add.length; n+=300) {
                push_apply(this, slice_call(to_add, n, n+300));
            }
        }
    }
});

var array1 = ['a','b','c'];
var array2 = ['d','e','f'];
var array3 = ['g','h','i'];

array1.pushArrayMembers(array2, array3);

document.body.textContent = JSON.stringify(array1, null, 4);

Top answer
1 of 1
186

If you want to modify the original array instead of returning a new array, use .push()...

array1.push.apply(array1, array2);
array1.push.apply(array1, array3);

I used .apply to push the individual members of arrays 2 and 3 at once.

or...

array1.push.apply(array1, array2.concat(array3));

To deal with large arrays, you can do this in batches.

for (var n = 0, to_add = array2.concat(array3); n < to_add.length; n+=300) {
    array1.push.apply(array1, to_add.slice(n, n+300));
}

If you do this a lot, create a method or function to handle it.

var push_apply = Function.apply.bind([].push);
var slice_call = Function.call.bind([].slice);

Object.defineProperty(Array.prototype, "pushArrayMembers", {
    value: function() {
        for (var i = 0; i < arguments.length; i++) {
            var to_add = arguments[i];
            for (var n = 0; n < to_add.length; n+=300) {
                push_apply(this, slice_call(to_add, n, n+300));
            }
        }
    }
});

and use it like this:

array1.pushArrayMembers(array2, array3);

var push_apply = Function.apply.bind([].push);
var slice_call = Function.call.bind([].slice);

Object.defineProperty(Array.prototype, "pushArrayMembers", {
    value: function() {
        for (var i = 0; i < arguments.length; i++) {
            var to_add = arguments[i];
            for (var n = 0; n < to_add.length; n+=300) {
                push_apply(this, slice_call(to_add, n, n+300));
            }
        }
    }
});

var array1 = ['a','b','c'];
var array2 = ['d','e','f'];
var array3 = ['g','h','i'];

array1.pushArrayMembers(array2, array3);

document.body.textContent = JSON.stringify(array1, null, 4);

๐ŸŒ
CodyHouse
codyhouse.co โ€บ blog โ€บ post โ€บ javascript-append-to-array
JavaScript quick tip - append to array with examples | CodyHouse
In the example above, we use the handleEvent function to handle multiple dragging events. If you are unfamiliar with this technique, take a look at this article on handling events in JavaScript and keeping them organized. In the storeDroppedFiles function, we update the dropped_files array: function storeDroppedFiles(new_files) { dropped_files.push(...new_files); } Each time the user drops new files, they will be appended to the dropped_files array.
Discussions

javascript - How to append something to an array? - Stack Overflow
How do I append an object (such as a string or number) to an array in JavaScript? More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to extend an existing JavaScript array with another array, without creating a new array - Stack Overflow
Though nowadays the arr.push(...arr2) is newer and better and a Technically Correct(tm) answer to this particular question. 2016-09-16T07:18:38.567Z+00:00 ... I hear you, but I searched for "javascript append array without creating a new array", then it is sad to see that a 60 times upvoted ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Three ways to append an item to an array (Mutative)
myArray = [...myArray, 'Pig'] :) More on reddit.com
๐ŸŒ r/learnjavascript
33
131
September 1, 2022
How to push an array into another array if the 1st item in the array to be pushed matches a string
Since the other comment is useless, I will help out. Your code is close. Firstly, you need a third arg in your forEach function to reference the array you are looping thru: just add a third arg called groups because you already called it that within. Second, you need to be cautious of the case of the letters. Third, do not push the array. You need to use concat to join them; otherwise you push the whole array into the other, not just the values. Go back and fix these things. Still will not be perfect but these are good things to note/fix. Edit. Just a few btws: your code also has an issue that if the first subarray contains a keyword, an index out of bound error will be thrown. Also, the array that is added to the array before it will still exist. Your array length will not change. Not sure if this is your intention or not, just pointing it out. More on reddit.com
๐ŸŒ r/learnjavascript
6
3
November 10, 2023
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Array โ€บ concat
Array.prototype.concat() - JavaScript - MDN Web Docs
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.
๐ŸŒ
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:
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);


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.

๐ŸŒ
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 - It uses push() combined with the spread operator to append elements of a2 to a1. ... It concatenates a1 and a2 into a new array, preserving the original arrays.
๐ŸŒ
Bobby Hadz
bobbyhadz.com โ€บ blog โ€บ javascript-append-one-array-to-another-array
How to Append one Array to Another in JavaScript | bobbyhadz
March 2, 2024 - On each iteration, we use the Array.push() method to add the element of the second array to the first array. You can also use a basic for loop to append one array to another array.
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ javascript-add-array-to-array-of-array
JavaScript - Add Array to Array of Array - GeeksforGeeks
July 23, 2025 - It can be used to add an array to an array of arrays by expanding both arrays into a new array. ... [...arrOfArr, newArr] creates a new array by spreading the elements of arrOfArr and then appending the newArr at the end.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript-append-array-at-the-end-of-another-array
JavaScript โ€“ Append Array At The End Of Another Array | GeeksforGeeks
November 28, 2024 - It uses push() combined with the spread operator to append elements of a2 to a1. ... It concatenates a1 and a2 into a new array, preserving the original arrays.
๐ŸŒ
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];
๐ŸŒ
Mastering JS
masteringjs.io โ€บ tutorials โ€บ fundamentals โ€บ array-append
JavaScript Append to Array - Mastering JS
let arr = ['c']; arr = arr.concat(['d', 'e']); arr; // ['c', 'd', 'e'] // You can also use `concat()` to add to the beginning of // the array, just make sure you call `concat()` on an array // containing the elements you want to add to the beginning. arr = ['a', 'b'].concat(arr); arr; // ['a', 'b', 'c', 'd', 'e'] Another common pattern is using the spread operator. let arr = ['c']; // Append to the end: arr = [...arr, 'd', 'e']; arr; // ['c', 'd', 'e'] // Append to the beginning: arr = ['a', 'b', ...arr]; arr; // ['a', 'b', 'c', 'd', 'e'] arr = ['c']; // Append to the middle: arr = ['a', 'b', ...arr, 'd', 'e']; arr; // ['a', 'b', 'c', 'd', 'e']
๐ŸŒ
Squash
squash.io โ€บ how-to-append-to-a-javascript-array
How To Append To A Javascript Array - Squash Labs
August 13, 2023 - In this example, we have an array ... Another way to append elements to a JavaScript array is by using the array concatenation operator, which is the plus sign (+)....
๐ŸŒ
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 - 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. ... The last is a bad practice, because of reasons. ( ... The middle one is more for splicing multiple arrays together.
๐ŸŒ
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 - By the end, youโ€™ll have a solid understanding of how to manipulate arrays in JavaScript, making your coding experience smoother and more efficient. The push() method is a straightforward way to append elements to an existing array. This method ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ how-to-append-an-element-in-an-array-in-javascript
How to append an element in an array in JavaScript? - GeeksforGeeks
November 15, 2024 - Appending an element to an array in JavaScript means adding a new item to the end of the array. This increases the arrayโ€™s length and makes room for additional data. JavaScript provides several simple methods to do this, each allowing you to add one or more items to the end of your 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.
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ javascript โ€บ examples โ€บ append-an-object-to-an-array
JavaScript Program to Append an Object to An Array | Vultr Docs
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 ...
๐ŸŒ
Favtutor
favtutor.com โ€บ articles โ€บ javascript-append
JavaScript Append Elements to an Array (4 Methods)
December 14, 2023 - Learn how to append new elements to an array in javascript using push, splice, concat method, and spread operator.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ javascript-array-insert-how-to-add-to-an-array-with-the-push-unshift-and-concat-functions
JavaScript Array Insert - How to Add to an Array with the Push, Unshift, and Concat Functions
August 25, 2020 - The first and probably the most common JavaScript array method you will encounter is push(). The push() method is used for adding an element to the end of an array.