Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/find-indexes
Like Array#findIndex() but return all indexes
https://github.com/shinnn/find-indexes
Last synced: 27 days ago
JSON representation
Like Array#findIndex() but return all indexes
- Host: GitHub
- URL: https://github.com/shinnn/find-indexes
- Owner: shinnn
- Created: 2016-12-20T11:43:22.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-05-08T09:43:43.000Z (over 7 years ago)
- Last Synced: 2024-09-28T02:05:49.700Z (about 2 months ago)
- Language: JavaScript
- Homepage: https://runkit.com/npm/find-indexes
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# find-indexes
[![NPM version](https://img.shields.io/npm/v/find-indexes.svg)](https://www.npmjs.com/package/find-indexes)
[![Bower version](https://img.shields.io/bower/v/find-indexes.svg)](https://github.com/shinnn/find-indexes/releases)
[![Build Status](https://travis-ci.org/shinnn/find-indexes.svg?branch=master)](https://travis-ci.org/shinnn/find-indexes)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/find-indexes.svg)](https://coveralls.io/r/shinnn/find-indexes)Like [`Array#findIndex()`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex), but return all indexes instead of the first one
```javascript
import findIndexes from 'find-indexes';findIndexes(['a', 'b', 'c', 'b'], val => val === 'b'); //=> [1, 3]
```## Installation
### [npm](https://www.npmjs.com/)
```
npm install find-indexes
```### [bower](https://bower.io/)
```
bower install find-indexes
```## API
```javascript
import findIndexes from 'find-indexes';
```### findIndexes(*array*, *fn*)
*array*: `Array`
*fn*: `Function`
Return: `Array`It returns all indexes of the the array that satisfy the provided testing function. Otherwise it returns an empty array.
```javascript
findIndexes([0.1, 0.5], Math.ceil); //=> [0, 1]
findIndexes([0.1, 0.5], Math.round); //=> [1]
findIndexes([0.1, 0.5], Math.floor); //=> []
```## Related projects
* [arr-indexes-of](https://github.com/shinnn/arr-indexes-of) - [`Array#indexOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf) version
* [str-indexes-of](https://github.com/shinnn/str-indexes-of) - [`String#indexOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) version## License
[Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/deed)