inspection

Array.prototype.concat

Returns a new array formed by joining the source with the provided arrays and/or values (one level of spread). Reach for it to merge arrays without mutating any of them.

arr.concat(...values)

Parameters

Parameter Purpose
...values Arrays (spread one level) or plain values to append
return value A new array; original arrays are unchanged (non-mutating)

Examples

console.log([1,2].concat([3,4]));

Logs: [1, 2, 3, 4]

console.log([1].concat(2, [3, 4], 5));

Logs: [1, 2, 3, 4, 5] (mixes values and arrays)

console.log([1].concat([[2, 3]]));

Logs: [1, [2, 3]] (only one level of spread)

const a = [1,2]; const b = [...a, 3, 4]; console.log(b);

Logs: [1, 2, 3, 4] (spread syntax is the modern equivalent)

Gotcha

Only spreads ONE level — nested arrays inside the arguments stay nested. Spread syntax `[...a, ...b]` is the modern replacement in most codebases.

Related methods

← All JS array methods · TypeScript vs JavaScript