JS Built-ins
← Array212 / 226
ArrayArray.prototype.valuesbeginner

Get Array Values as Array

πŸ“– Usage Example
const arr = ['x', 'y', 'z']
const iter = arr.values()
iter.next().value  // β†’ 'x'

Use values() to get an iterator that yields each element of the array in order.

Array.prototype.values

values() returns an Array Iterator that yields each value in the array. You can convert it to a plain array using Array.from.

Implement getValues which converts arr.values() to a regular array using Array.from.

πŸ’‘ Hints (2)
  • β€’ Use Array.from(arr.values()) to materialise the iterator into an array
  • β€’ The result contains the same values in the same order as the original