JS Built-ins
Functionapplyintermediate

Function.prototype.apply() β€” push multiple elements

πŸ“– Usage Example
const args = [1, 2, 3]
function sum(a, b, c) { return a + b + c }
sum.apply(null, args)  // β†’ 6

apply() is useful when arguments are already in an array.

apply() with Array.push

[].push.apply(target, source) appends all elements of source into target β€” useful before spread syntax.

Challenge: Use [].push.apply(arr, [2, 3]) on arr = [1] and verify arr equals [1, 2, 3].

πŸ’‘ Hints (1)
  • β€’ `[].push.apply(target, items)` is equivalent to `target.push(...items)`.