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

Array.prototype.shift() β€” consume the first word

πŸ“– Usage Example
const words = ['hello', 'world', 'foo']
const head = words.shift()  // β†’ 'hello'
words  // β†’ ['world', 'foo']

Use shift() to consume the first element of a word or message queue.

shift() as "consume first"

Use shift() to consume and process the first element of a list one at a time β€” a common pattern in command parsing or token processing.

const words = ['hello', 'world']
const first = words.shift() // 'hello', words === ['world']
πŸ’‘ Hints (2)
  • β€’ `shift()` removes the first element and returns it in one call.
  • β€’ Directly `return words.shift()` is the idiomatic approach.