# array-filter-n

> Get the first N elements of an array which satisfy a given condition. Fast!

Latest version **1.1.0** (published 2015-11-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install array-filter-n
pnpm add array-filter-n
yarn add array-filter-n
bun add array-filter-n
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2015-11-05 |
| First published | 2015-10-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | ashish shubham |
| Maintainers | ashubham |
| Keywords | first-n, filter-n, filter, array, first, n |

## Links

- npm: https://www.npmjs.com/package/array-filter-n
- Repository: https://github.com/ashubham/array-filter-n
- Issues: https://github.com/ashubham/array-filter-n/issues
- npm.io page: https://npm.io/package/array-filter-n

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.1.0 (latest) — 2015-11-05
- 1.0.8 — 2015-11-05
- 1.0.7 — 2015-10-27
- 1.0.6 — 2015-10-20
- 1.0.5 — 2015-10-09
- 1.0.4 — 2015-10-01
- 1.0.2 — 2015-10-01
- 1.0.2222 — 2015-10-01
- 1.0.3 — 2015-10-01
- 1.0.333 — 2015-10-01

## README

# array-filter-n 	

<a href="https://travis-ci.org/ashubham/array-filter-n">
  <img src="https://api.travis-ci.org/ashubham/array-filter-n.svg?branch=master" class="badge">
</a>

The filterN() method creates a new array with the first N elements that pass the test implemented by the provided function. Fast!

## Syntax

`filterN(inputArr, N, checkFn[, thisArg])`

The checkFn is the standard EcmaScript `function (elem, index, array)`

`thisArg` if supplied is set as the `this` context for `checkFn`.

## Usage

```javascript
var filterN = require('array-filter-n');

var filter4even = 
    filterN([12, 8, 3, 1, 0, 4, 7, 9, 12], 4, function(i) { return !i%2});
//=> [12, 8, 0, 4]

// works also on strings
var filter3nums = 
    filterN('n0d3_R0ck5', 3, function(c) { return !isNaN(parseInt(c)); });
//=> [0, 3, 0]

// Fastened safety belts
var first4pallindromes = 
    filterN(['aat', 'aba', 'pop'], 5, function (s) { 
        s == s.split('').reverse().join(''); 
    });
//=> ['aba', 'pop']

var crazy = filterN([1,2,3,4], -3);
//=> []

var notSoCrazy = filterN([1,2,3,4], 3);
//=> [1, 2, 3]
```

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