# indexed-filter

> Array#filter() with also detecting indexes of filtered values

Latest version **1.0.3** (published 2018-05-01) · ISC license · 0 weekly downloads

## Install

```sh
npm install indexed-filter
pnpm add indexed-filter
yarn add indexed-filter
bun add indexed-filter
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2018-05-01 |
| First published | 2015-10-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Shinnosuke Watanabe |
| Maintainers | shinnn |
| Keywords | arr, array, filter, filtering, index, indexed, value, values, client-side, browser |

## Links

- npm: https://www.npmjs.com/package/indexed-filter
- Repository: https://github.com/shinnn/indexed-filter
- Homepage: https://github.com/shinnn/indexed-filter#readme
- Issues: https://github.com/shinnn/indexed-filter/issues
- npm.io page: https://npm.io/package/indexed-filter

## Dependencies (1)

- [append-type](https://npm.io/package/append-type.md) ^1.0.1

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2018-05-01
- 1.0.2 — 2018-05-01
- 1.0.1 — 2018-04-26
- 1.0.0 — 2015-10-13
- 0.0.0 — 2015-10-13

## README

# indexed-filter

[![npm version](https://img.shields.io/npm/v/indexed-filter.svg)](https://www.npmjs.com/package/indexed-filter)
[![Build Status](https://travis-ci.org/shinnn/indexed-filter.svg?branch=master)](https://travis-ci.org/shinnn/indexed-filter)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/indexed-filter.svg)](https://coveralls.io/github/shinnn/indexed-filter)

[`Array#filter()`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) with also appending indexes of filtered values to the result

```javascript
const arr = [1, 'foo', 2, 'bar'];

arr.filter(v => typeof v === 'string');
//=> ['foo', 'bar']

indexedFilter(arr, v => typeof v === 'string');
//=> [{index: 1, value: 'foo'}, {index: 3, value: 'bar'}]
```

## Installation

[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/getting-started/what-is-npm).

```
npm install indexed-filter
```

## API

```javascript
import indexedFilter from 'indexed-filter';
```

### indexedFilter(*array*, *filterFn* [, *thisObject*])

*array*: `Array`  
*filterFn*: `Function`  
*thisObject*: (any value)  
Return: `Array`

The API is very similar to [`Array.prototype.filter()`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/filter). There are only two differences:

* You pass in the array as the first argument instead of calling the `.filter()` method on the array instance.
* Each filtered result is an object with tow properties, `index` (array index integer) and `value` (array element).

```javascript
indexedFilter([0, [1], [2], '3', [5]], function(val, index, arr) {
  return this.isArray(val) && index % 2 === 0 && index < arr.length * 0.5;
}, Array);
//=> [{index: 2, value: [2]}]
```

## License

[ISC License](./LICENSE) © 2018 Shinnosuke Watanabe

---
_Source: https://npm.io/package/indexed-filter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
