Returns an array of the values of an Array, Iterator, Object, Map, Set, or Typed Array. Useful for when you need the values of a collection object but aren’t sure what type of collection you’ll be given.
Requires Node.js 6.0.0 or above.
npm i values-array
The module exports a single function.
Bindable: c
(Array, Iterator, Object, Map, Set, or Typed Array)
An array of values from the collection.
const values = require('values-array')
values(['a', 'b']) // ['a', 'b']
// Supports the bind operator
['a', 'b']::values() // ['a', 'b']
const values = require('values-array')
function * gen () {
yield 'a'
yield 'b'
}
values(gen()) // ['a', 'b']
const values = require('values-array')
const map = new Map()
map.set('key', 'value')
values(map) // ['value']
const values = require('values-array')
values({key: 'value'}) // ['value']
// Supports the bind operator
const obj = {key: 'value'}
obj::values() // ['value']
const values = require('values-array')
const set = new Set()
set.add('first')
set.add('second')
values(set) // ['first', 'second']
const values = require('values-array')
const typedArray = new Int32Array(new ArrayBuffer(4))
values(typedArray) // [0]