Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jonschlinkert/filter-array

Iterates over the elements in an array, returning an array with only the elements for which the callback returns truthy.
https://github.com/jonschlinkert/filter-array

array filter javascript node nodejs

Last synced: 28 days ago
JSON representation

Iterates over the elements in an array, returning an array with only the elements for which the callback returns truthy.

Awesome Lists containing this project

README

        

# filter-array [![NPM version](https://badge.fury.io/js/filter-array.svg)](http://badge.fury.io/js/filter-array)

> Iterates over the elements in an array, returning an array with only the elements for which the callback returns truthy.

## Install with [npm](npmjs.org)

```bash
npm i filter-array --save
```

## Usage

### [filterArray](index.js#L36)

Filter array against given glob patterns, regex or given function.

**Params**

* `arr` **{Array}**: array to filter
* `filters` **{Array|String|Function|RegExp}**
* `opts` **{Object}**: options to pass to [micromatch](https://github.com/jonschlinkert/micromatch)
* `returns` **{Array}**

**Example**

```js
var filter = require('filter-array');

filter(['a', 'b', 'c', 'b', 'c', 'e'], function(ele) {
return ele === 'a' || ele === 'b';
});

//=> ['a', 'b', 'b']
```

For more examples see the [tests](./test.js)

## Related

* [arr-filter](https://github.com/jonschlinkert/arr-filter): Faster alternative to javascript's native filter method.
* [filter-object](https://github.com/jonschlinkert/filter-object): Return a copy of an object, filtered to have only keys that match the given… [more](https://github.com/jonschlinkert/filter-object)
* [micromatch](https://github.com/jonschlinkert/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. Just… [more](https://github.com/jonschlinkert/micromatch)

## Run Tests

Install dev dependencies:

```bash
npm i -d && npm test
```

## Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/filter-array/issues)

## Author

**Jon Schlinkert**

+ [github/jonschlinkert](https://github.com/jonschlinkert)
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)

## License

Copyright (c) 2014-2015 Jon Schlinkert
Released under the MIT license.

***

_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on May 01, 2015._