JS Built-ins
← Array216 / 226
ArrayArray.prototype.valuesadvanced

values() Is the Default Iterator

πŸ“– Usage Example
const arr = [1, 2, 3]
const a = [...arr.values()]
const b = [...arr[Symbol.iterator]()]
// a and b are identical

values() is equivalent to the default Symbol.iterator of an array.

Array.prototype.values β€” Default Iterator

The default array iterator (arr[Symbol.iterator]) is identical to arr.values. Both yield elements in index order, so spreading them produces the same result.

Implement valuesIteratorIsDefault which returns true if [...arr[Symbol.iterator]()].join() equals [...arr.values()].join().

πŸ’‘ Hints (2)
  • β€’ arr[Symbol.iterator] and arr.values reference the same underlying function
  • β€’ Use .join() to compare the two iterator outputs as strings