JS Built-ins
← Array144 / 226
ArrayArray.prototype.pushintermediate

Array.prototype.push() β€” return value is the new length

πŸ“– Usage Example
const arr = ['a', 'b']
const newLength = arr.push('c')  // β†’ 3
arr  // β†’ ['a', 'b', 'c']

push() returns the new length of the array, which you can use without a separate length check.

push() returns the new length

Unlike many array methods, push() returns the new length of the array β€” not the element added, not the array itself.

const len = [1, 2].push(3) // len === 3

This is a common source of bugs when developers expect it to return the pushed element.

πŸ’‘ Hints (2)
  • β€’ `push()` does NOT return the pushed element β€” it returns the new array length.
  • β€’ After pushing one element to a 2-element array, the new length is 3.