JS Built-ins
← Array38 / 226
ArrayArray.prototype.concatbeginner

Array.prototype.concat() β€” join multiple arrays

πŸ“– Usage Example
const a = [1]
const b = [2, 3]
const c = [4, 5]
a.concat(b, c)  // β†’ [1, 2, 3, 4, 5]

Pass multiple arrays to concat() to join them all in a single call.

Array.prototype.concat() β€” multiple arguments

concat() can accept multiple arrays as arguments, joining them all in one call.

Challenge: Implement joinAll(arrays) that concatenates an array of number arrays into a single flat array.

joinAll([[1, 2], [3, 4], [5]]) // β†’ [1, 2, 3, 4, 5]
joinAll([[1], [], [2]])        // β†’ [1, 2]
πŸ’‘ Hints (2)
  • β€’ Use spread syntax: `[].concat(...arrays)` to spread the array of arrays as individual arguments.
  • β€’ Alternatively, `arrays.reduce((acc, arr) => acc.concat(arr), [])` works too.