JS Built-ins
← Array139 / 226
ArrayArray.prototype.popintermediate

Array.prototype.pop() β€” verify array is mutated

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

pop() mutates the original array β€” if you need immutability, use slice(0, -1) instead.

Array.prototype.pop() β€” mutation

pop() is a mutating method: it changes the original array. After popping, the array has one fewer element. This exercise focuses on observing that side-effect.

Challenge: Implement popAndCheck(arr) that pops from arr and returns the mutated array (not the popped value).

popAndCheck([1, 2, 3]) // β†’ [1, 2]
popAndCheck([10])      // β†’ []
πŸ’‘ Hints (2)
  • β€’ Call `arr.pop()` and then `return arr` β€” the array has already been mutated.
  • β€’ Note that the returned array is the **same object** as the input.