first-value
v1.0.0
Published
Retrieves the first value of an Array, Iterator, Object, Map, Set, or Typed Array.
Downloads
19
Maintainers
Readme
first-value
Retrieves the first value of an Array, Iterator, Object, Map, Set, or Typed Array.
Returns undefined if the collection is empty.
Installation
Requires Node.js 7.0.0 or above.
npm i first-valueAPI
The module exports a single function.
Parameter
Bindable: c (Array, Iterator, Object, Map, Set, or Typed Array): The collection of entries/values.
Return Value
The first value in the collection.
Example
const firstValue = require('first-value')
firstValue([1, 2, 3]) // 1
firstValue({a: 1, b: 2}) // 1
firstValue(new Set([1, 2, 3])) // 1
firstValue(new Map([['a', 1], ['b', 2]])) // 1
firstValue([]) // undefined