JS Built-ins
← Array164 / 226
ArrayArray.prototype.shiftintermediate

Array.prototype.shift() β€” mutation and same reference

πŸ“– Usage Example
const arr = ['a', 'b', 'c']
arr.shift()
console.log(arr)  // β†’ ['b', 'c']  (mutated!)

shift() mutates the original array and re-indexes all remaining elements.

shift() mutates the array

shift() modifies the array in place: after calling it, the array is one element shorter and all remaining elements shift left by one position.

const arr = [10, 20, 30]
arr.shift()
// arr === [20, 30]
πŸ’‘ Hints (2)
  • β€’ Call `arr.shift()` to mutate, then `return arr`.
  • β€’ `shift()` reduces the array length by 1 and shifts all remaining elements left.