JavaScript engines typically put a cap on the number of arguments you can pass to a method before they throw an error, for example, the below throws an error in Chrome:

const arr = Array(150000).fill(0);
const arr2 = [];
arr2.push(...arr);

Whereas when using .concat(), you'll only be passing the one array to the method, so you don't get the error:

const arr = Array(150000).fill(0);
const arr2 = [];
const res = arr2.concat(arr);
// res is an array with 150000 `0`s

Additionally, with .push() + ..., you're effectively doing two iterations over your iterable/array, one for unpacking its contents as arguments to the .push() method, and then another for one done internally by the .push() method itself to iterate through each of the arguments and append it to the target array.

Another noticeable difference is in what both methods return, .concat() will return a new array and won't modify the target, which can be useful in methods such as .map() or .reduce() where you need to produce a new array without mutating the original. Whereas .push() will return the length of the updated array and will modify the target, so that is another difference to consider.

As pointed out by @T.J. Crowder, the iterator of arrays which is invoked when using the spread syntax ... does not preserve blanks in sparse arrays, instead it unpacks them as undefined values, meaning that if the array you're specifying is sparse when using .push() + ... you'll get undefined for the blanks, whereas the blanks will be preserved when using .concat() directly:

const arr = Array(3); // this is a sparse array, [empty × 3], not to be confused with [undefined, undefined, undefined]
const arr2 = [];
arr2.push(...arr); // Here `...` becomes: arr2.push(undefined, undefined, undefined);
console.log(arr2); // [undefined, undefined, undefined]

const arr3 = [];
console.log(arr3.concat(arr)); // Retains empties: [empty × 3]
See browser console for results

Answer from Nick Parsons on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › concat
Array.prototype.concat() - JavaScript | MDN
The concat() method of Array instances is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.
🌐
W3Schools
w3schools.com › jsref › jsref_concat_array.asp
JavaScript Array concat() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST ... Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean
Discussions

javascript - How to join / combine two arrays to concatenate into one array? - Stack Overflow
It is also the fastest way to concatenate arrays in JavaScript today. More on stackoverflow.com
🌐 stackoverflow.com
Better performing alternative to Array.unshift
Adding things to the front of an array is slower than adding something to the end because it has to shift all the other elements in the array back by one. When you add something to the end, nothing else has to change. So if you can change your code to add to the end instead, that would be better. But this is also one of those micro-optimizations that you probably won't see an impact from unless dealing with large arrays in a hot code path. More on reddit.com
🌐 r/learnjavascript
14
1
December 7, 2022
Logical concatenation for large arrays
When dealing with large arrays (10^6 > elements), concatenating them can be very memory-consuming. This solution joins arrays logically, turning a list of arrays into an iterable, with additional "length" and "at" access. See also the source repo: https://github.com/vitaly-t/chain-arrays . const a = [1, 2]; const b = [3, 4]; const c = [5, 6]; for (const value of chainArrays(a, b, c)) { console.log(value); //=> 1, 2, 3, 4, 5, 6 } for (const value of chainArraysReverse(a, b, c)) { console.log(value); //=> 6, 5, 4, 3, 2, 1 } How good is performance of such logical iteration? Here's a simple test: import {chainArrays} from './chain-arrays'; const r = 10_000_000; const a = Array(r).fill(1); const b = Array(r).fill(2); const c = Array(r).fill(3); const d = Array(r).fill(4); const e = Array(r).fill(5); const start = Date.now(); let sum = 0; for (const i of chainArrays(a, b, c, d, e)) { sum += i; } console.log(`${Date.now() - start}ms`); //=> ~100ms Above, we iterate over 5 arrays, with 10 mln elements each, within 100ms. For comparison, using the spread syntax for the same: let sum = 0; for (const i of [...a, ...b, ...c, ...d, ...e]) { sum += i; } console.log(`${Date.now() - start}ms`); //=> ~1175ms That took 11.7 times longer, while also consuming tremendously more memory. The same iteration via index is roughly 2 times slower, as it needs to calculate the source array index every time you use "at" function: let sum = 0; const chain = chainArrays(a, b, c, d, e); for (let t = 0; t < chain.length; t++) { sum += chain.at(t)!; } console.log(`${Date.now() - start}ms`); //=> ~213ms More on reddit.com
🌐 r/javascript
56
8
October 9, 2023
JavaScript String method: Split, Concat, and Join
Hopefully this solution and its comments are helpful: https://codepen.io/pigparlor/pen/gOQBXOd?editors=0010 function splitAndMerge(string, separator) { const words = string.split(' '); // e.g. ['My', 'name', 'is', 'John'] const charsJoined = words.map(word => word .split('') // e.g. [['M', 'y'], ['n', 'a', 'm', 'e'], ['i', 's'], ['J', 'o', 'h', n']] .join(separator) //e.g. ['M-y', 'n-a-m-e', 'i-s', 'J-o-h-n'] ); const wordsJoined = charsJoined.join(' '); // e.g. 'M-y n-a-m-e i-s J-o-h-n' return wordsJoined; } More on reddit.com
🌐 r/learnjavascript
3
5
July 26, 2023
Top answer
1 of 2
13

JavaScript engines typically put a cap on the number of arguments you can pass to a method before they throw an error, for example, the below throws an error in Chrome:

const arr = Array(150000).fill(0);
const arr2 = [];
arr2.push(...arr);

Whereas when using .concat(), you'll only be passing the one array to the method, so you don't get the error:

const arr = Array(150000).fill(0);
const arr2 = [];
const res = arr2.concat(arr);
// res is an array with 150000 `0`s

Additionally, with .push() + ..., you're effectively doing two iterations over your iterable/array, one for unpacking its contents as arguments to the .push() method, and then another for one done internally by the .push() method itself to iterate through each of the arguments and append it to the target array.

Another noticeable difference is in what both methods return, .concat() will return a new array and won't modify the target, which can be useful in methods such as .map() or .reduce() where you need to produce a new array without mutating the original. Whereas .push() will return the length of the updated array and will modify the target, so that is another difference to consider.

As pointed out by @T.J. Crowder, the iterator of arrays which is invoked when using the spread syntax ... does not preserve blanks in sparse arrays, instead it unpacks them as undefined values, meaning that if the array you're specifying is sparse when using .push() + ... you'll get undefined for the blanks, whereas the blanks will be preserved when using .concat() directly:

const arr = Array(3); // this is a sparse array, [empty × 3], not to be confused with [undefined, undefined, undefined]
const arr2 = [];
arr2.push(...arr); // Here `...` becomes: arr2.push(undefined, undefined, undefined);
console.log(arr2); // [undefined, undefined, undefined]

const arr3 = [];
console.log(arr3.concat(arr)); // Retains empties: [empty × 3]
See browser console for results

2 of 2
0

I don't understand if you want to add an Array into another or just make one Array made of two Arrays.

In the last case this is a short way to concatenate Arrays too by using spread syntax:

const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];
const combinedArray = [...arr1, ...arr2];
console.log(combinedArray);

Note:

If you need to preserve the original arrays, this code above is suitable, like the concat() method.

The push() method will modify your initial Array.

🌐
Dmitri Pavlutin
dmitripavlutin.com › javascript-merge-arrays
3 Ways to Merge Arrays in JavaScript
January 28, 2023 - JavaScript offers multiple ways to merge arrays. You can use either the spread operator [...array1, ...array2], or a functional way [].concat(array1, array2) to merge 2 or more arrays.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › join
Array.prototype.join() - JavaScript | MDN
The join() method of Array instances creates and returns a new string by concatenating all of the elements in this array, separated by commas or a specified separator string. If the array has only one item, then that item will be returned without using the separator.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-array-concat-method
JavaScript Array concat() Method - GeeksforGeeks
The concat() method is used to join two or more arrays together.
Published   January 19, 2026
Find elsewhere
🌐
Mimo
mimo.org › glossary › javascript › array-concatenation
JavaScript Array Concatenate: Syntax, Usage, and Examples
The two most common and recommended ways to concatenate arrays in JavaScript are the concat() method and the spread operator (...). Both create a new array without changing the original arrays.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-merge-arrays-in-javascript-array-concatenation-in-js
How to Merge Arrays in JavaScript – Array Concatenation in JS
November 28, 2022 - You can learn more about this operator in this article: Spread Operator Simplified. You use the concat method of arrays to combine the contents of an array with new values to form a new array.
🌐
SamanthaMing
samanthaming.com › tidbits › 49-2-ways-to-merge-arrays
2 Ways to Merge Arrays in JavaScript | SamanthaMing.com
Here are 2 ways to combine your arrays and return a NEW array. I like using the Spread operator. But if you need older browser support, you should use Concat.
🌐
JavaScript in Plain English
javascript.plainenglish.io › efficiently-merging-arrays-in-javascript-32993788a8b2
How to Efficiently Merge Arrays in JavaScript | by Chad Campbell | JavaScript in Plain English
February 18, 2022 - For larger Arrays, with more elements, use the concat function. Regardless of your scenario, test your code with the most number of elements you expect. The goal is to create code that works, is efficient, and easy-to-read. In this article, you saw three ways to merge two Arrays in JavaScript.
🌐
Dillion's Blog
dillionmegida.com › p › array-concat
Array concat method simplified - Dillion's Blog
November 22, 2022 - #javascript · Here's a video if you'd prefer that: https://youtu.be/a5kkO4KMvUE · The concat method in JavaSript is used to concatenate the contents of an existing array with new values to form a new array.
🌐
DEV Community
dev.to › samanthaming › 2-ways-to-merge-arrays-in-javascript-42d1
2 Ways to Merge Arrays in JavaScript - DEV Community
February 25, 2019 - Here are 2 ways to combine your arrays and return a NEW array. Here are 2 ways to combine your arrays and return a NEW array. Let's look at how we do that using spread and concat. Tagged with javascript, webdev, beginners, codenewbie.
🌐
Dustin John Pfister
dustinpfister.github.io › 2020 › 07 › 13 › js-array-concat
The array concat method and some other ways of adding two arrays together | Dustin John Pfister at github pages
July 12, 2021 - So there is adding two strings or numbers together with the addition operator in javaScript, but then there is adding two or more objects together including Arrays and how such an operation should be handled. In the array prototype object there is the array concat method that can be used to create a new array that is the concatenation of two or more arrays, or values by themselves actually.
🌐
Codedamn
codedamn.com › news › javascript
JavaScript concat array explained – How to merge arrays in JS
June 24, 2023 - In this example, array1 contains three numbers, while array2 contains three strings. The JavaScript concat() method is used to merge two or more arrays into a single array.
🌐
Envato Tuts+
code.tutsplus.com › home › coding fundamentals
Merge Arrays in JavaScript: With and Without Duplicates | Envato Tuts+
February 19, 2023 - The array items will be inserted in the same order as the source. The concat function allows you to merge two or more arrays.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Array methods
slice(start, end) – creates a new array, copies elements from index start till end (not inclusive) into it. concat(...items) – returns a new array: copies all members of the current one and adds items to it.
🌐
YouTube
youtube.com › watch
JS Array Methods Explained #15 - CONCAT Method - YouTube
In this video, the part 15 of my Array Methods Explained series, I simplified the concat method of arrays.This method is used to concatenate the contents of ...
Published   November 23, 2022
🌐
Medium
medium.com › @devnewbs › basics-of-javascript-array-concat-method-1de1c27eaa27
Basics of Javascript · Array · concat() (method)
December 20, 2023 - The second example leverages multiple arrays in the argument list. Again, in the order they have been added, their respective content was appended at the end of the newly created array. Lastly in the third invocation of the concat() method, we combine individual elements with arrays.
🌐
DEV Community
dev.to › smlka › fun-with-arrayprototypeconcat-554l
Merge array-like objects by Array.prototype.concat() - DEV Community
June 27, 2024 - Let's dive into the Array.prototype.concat() method in JavaScript. This handy method helps you merge arrays, creating a new array with elements from the arrays you provide.
Top answer
1 of 3
311
Copyvar a = ['a','b','c'];
var b = ['d','e','f'];
var c = a.concat(b); //c is now an an array with: ['a','b','c','d','e','f']
console.log( c[3] ); //c[3] will be 'd'
2 of 3
26

Using ES6 JavaScript - spread syntax:

Copyconst a = ['a', 'b', 'c'];
const b = ['d', 'e', 'f'];

const c = [...a, ...b]; // c = ['a', 'b', 'c', 'd', 'e', 'f']

It is also the fastest way to concatenate arrays in JavaScript today.


However, when dealing with large arrays, it is more efficient to chain them (concatenate logically):

Copyfunction chainArrays<T>(...arr: T[][]): Iterable<T> {
    return {
        [Symbol.iterator](): Iterator<T> {
            let i = 0, k = -1, a: T[] = [];
            return {
                next(): IteratorResult<T> {
                    while (i === a.length) {
                        if (++k === arr.length) {
                            return {done: true, value: undefined};
                        }
                        a = arr[k];
                        i = 0;
                    }
                    return {value: a[i++], done: false};
                }
            };
        }
    }
}

// usage example:

const a = [1, 2];
const b = [3, 4];
const c = [5, 6];

for (const value of chainArrays(a, b, c)) {
    console.log(value); //=> 1, 2, 3, 4, 5, 6
}

Above, we have to use while(i === a.length) logic in order to skip all empty arrays, while also for jumping to the next array at the end of the current one.

A generator approach for the same is much simpler, while also slower:

Copyfunction* chainArrays<T>(...arr: T[][]) {
    for (const i of arr)
        for (const v of i)
            yield v;
}

// test:

for (const value of chainArrays(a, b, c)) {
    console.log(value); //=> 1, 2, 3, 4, 5, 6
}

Internally, a generator is translated into a more verbose IterableIterator, which used to perform slower than a manual iterable, but JavaScript engines keep improving, so it's for you to test it out in your environment ;) But I tested it under Node v20, and on average the manual iterable performs 2 times faster than our generator here.

For a complete TypeScript implementation (including reversed logic), see this gist, or this repo.