JS Built-ins
← Array209 / 226
ArrayArray.prototype.unshiftintermediate

unshift Returns the New Length

πŸ“– Usage Example
const arr = ['b']
const len = arr.unshift('a')  // β†’ 2 (new length)
arr  // β†’ ['a', 'b']

unshift() returns the new length of the array after insertion.

Array.prototype.unshift β€” Return Value

The return value of unshift is the new length of the array after insertion β€” not the modified array itself.

Implement unshiftReturns which returns the value of arr.unshift(val) directly.

πŸ’‘ Hints (2)
  • β€’ Return arr.unshift(val) directly β€” its return value is the new length
  • β€’ Unlike push, the return value is a number, not the array