1.0.0 • Published 8 years ago

@f/find-index v1.0.0

Weekly downloads
14
License
MIT
Repository
github
Last release
8 years ago

find-index

Build status Git tag NPM version Code style

Find the index of an item in an array, given a predicate

Installation

$ npm install @f/find-index

Usage

var findIndex = require('@f/find-index')

findIndex([1, 2, 3], n => n === 3) === 2

API

findIndex(arr, fn, fromIndex)

  • arr - Array to search
  • fn - Predicate function that is called on each item. If it returns true, the index of that item is returned from findIndex.
  • fromIndex - Optional. Defaults to 0. The starting place in the array to search from.

Returns: The index of the first item that fn returns true for. If no such item is found, returns -1.

License

MIT