@bemoje/arr-first-where
Return the first element of an array where the callback returns true.
Version
Travis CI
Dependencies
Stats
Donate
Installation
npm install @bemoje/arr-first-where
npm install --save @bemoje/arr-first-where
npm install --save-dev @bemoje/arr-first-where
Usage
import arrFirstWhere from '@bemoje/arr-first-where'
const arr = [1, 2, 3, 4, 5]
arrFirstWhere(arr, (element) => {
return element >= 3
})
//=> 3
arrFirstWhere(arr, (element) => {
return element >= 6
})
//=> null
Tests
Uses Jest to test module functionality. Run tests to get coverage details.
npm run test
API
arrFirstWhere
Return the first element of an array where the callback returns true.
Parameters
Returns
any The first element to satisfy the condition
predicate
Type: Function
Parameters
-
element
any The current array element -
index
number The current index -
array
Array The array being itereated