Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/jonschlinkert/filter-array
- Owner: jonschlinkert
- License: mit
- Created: 2014-12-12T11:54:06.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-05-02T03:19:28.000Z (over 9 years ago)
- Last Synced: 2024-10-04T19:45:10.729Z (about 2 months ago)
- Topics: array, filter, javascript, node, nodejs
- Language: JavaScript
- Size: 147 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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._