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

Array.prototype.pop() β€” remove the last word

πŸ“– Usage Example
const words = ['foo', 'bar', 'baz']
const last = words.pop()  // β†’ 'baz'
words  // β†’ ['foo', 'bar']

Use pop() to consume the last string element from a queue or word list.

Array.prototype.pop() β€” string arrays

pop() works on any typed array, not just numbers. This exercise applies it to a string array to remove and return the last word in a list.

Challenge: Implement removeLastWord(words) that pops and returns the last string from the array.

removeLastWord(['hello', 'world']) // β†’ 'world'
removeLastWord(['only'])           // β†’ 'only'
πŸ’‘ Hints (2)
  • β€’ `pop()` works identically for string arrays β€” it removes and returns the last element.
  • β€’ The return type is `string | undefined` because `pop()` on an empty array returns `undefined`.