@bemoje/arr-first-where

1.0.2 • Public • Published

@bemoje/arr-first-where

Return the first element of an array where the callback returns true.

Version

NPM version

Travis CI

dependencies

Dependencies

dependencies

Stats

NPM downloads Forks

Donate

Buy Me A Beer donate button PayPal donate button

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
  • arr Array The array to iterate

  • callback predicate The callback(element, index, array): boolean

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

Returns

boolean

Package Sidebar

Install

npm i @bemoje/arr-first-where

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

9.32 kB

Total Files

5

Last publish

Collaborators

  • bemoje