Master Code
On The Go

Learn. Practice. Build.

Home › Code Snippets › JavaScript › Reference › concat()

JavaScript Reference

Array.prototype.concat()

Merge arrays into a new array without mutating. Returns a shallow copy.

Last updated: October 2026

Definition: Array.prototype.concat() merges two or more arrays into a new array. It does not modify the original arrays. It accepts both arrays and individual values as arguments and flattens array arguments by one level [citation:1][citation:13].

🎬 Live Example

Five concat patterns. Click any button to see the output.

Input:

                
Output:

            

💡 concat never mutates. The originals stay untouched.

📝

Basic Syntax

array.concat(value1, value2, ...)

// Returns a new array
// Does NOT mutate the original
// Flattens array arguments by one level

🎯 Syntax & Parameters

Parameter Type Description
valueNanyArrays or values to merge. Array args are flattened one level.
1

Merge Two Arrays

const a = [1, 2];
const b = [3, 4];
const merged = a.concat(b);
// merged: [1, 2, 3, 4]
// a:      [1, 2]  (unchanged)
// b:      [3, 4]  (unchanged)
2

Merge Multiple Arrays

const result = [1].concat([2], [3], [4]);
// [1, 2, 3, 4]

// Chainable
const chained = [1].concat([2]).concat([3]);
// [1, 2, 3]

Pro tip: concat returns a new array, so it's chainable — unlike push which returns a number.

3

Mix Arrays and Values

const arr = [1, 2];
arr.concat(3, 4, [5, 6]);
// [1, 2, 3, 4, 5, 6]

// Values are added as single elements
// Array args are spread one level
4

Only One Level Deep

const nested = [1, 2].concat([[3, 4]]);
// [1, 2, [3, 4]]  ← NOT fully flattened

// Use flat() for deeper flattening:
[1, 2].concat([[3, 4]]).flat();
// [1, 2, 3, 4]

Important: concat flattens array arguments by one level only. Nested arrays inside those arguments stay nested.

5

Real-World: Immutable State Merge

// React / Redux pattern
const initialState = { items: [1, 2] };

// ❌ Mutating
// state.items.push(3);

// ✅ Non-mutating with concat
const newState = {
    ...state,
    items: state.items.concat([3])
};
// state.items:    [1, 2]
// newState.items: [1, 2, 3]

This is the classic immutable update pattern — concat never surprises you by mutating.

🎯 concat vs push vs spread vs flat

Method Mutates? Flatten depth
concatNo1 level
pushYesNone
[...a, ...b]No1 level
flat()NoConfigurable

⚠️ Common Mistakes

❓ Frequently Asked Questions

What does Array.concat() do in JavaScript?

Array.concat() merges two or more arrays into a new array without modifying the original arrays. It returns a new array containing elements from the original array followed by the elements of each argument.

What is the difference between concat and push?

concat returns a new array and does not modify the originals. push mutates the original array by adding elements to it. Use concat for immutable merging, push for in-place additions.

Does concat flatten nested arrays?

No. concat only flattens one level of array arguments. Nested arrays inside those arguments remain nested. Use flat() or flatMap() for deeper flattening.

Can concat merge arrays and values together?

Yes. concat accepts both arrays and individual values. arr.concat([1, 2], 3, 4) adds the array elements followed by the numbers 3 and 4 to the new array.

Is concat faster than spread for merging arrays?

They are similar in performance for small arrays. Spread ([...a, ...b]) is more modern and readable. concat can be marginally faster on very large arrays in some engines, but the difference is rarely significant.

🎯 What's Next?

← All JavaScript Reference