JS Built-ins
← Array215 / 226
ArrayArray.prototype.valuesintermediate

Spread an Array Values Iterator

πŸ“– Usage Example
const arr = [10, 20, 30]
const copy = [...arr.values()]  // β†’ [10, 20, 30]

Spread values() into a new array to create a shallow copy using the iterator protocol.

Array.prototype.values β€” Spread

Because values() returns an iterable iterator, you can spread it with [...arr.values()] to get a new array β€” a concise alternative to Array.from.

Implement spreadValues which uses the spread operator on arr.values() to produce a new array.

πŸ’‘ Hints (2)
  • β€’ Use [...arr.values()] β€” the spread operator consumes any iterable
  • β€’ This is equivalent to Array.from(arr.values())