Skip to content

Filter an array or arguments by JavaScript native type (e.g. functions, strings, etc).

License

Notifications You must be signed in to change notification settings

jonschlinkert/filter-type

Repository files navigation

filter-type NPM version

Filter items from an array or arguments that match the specified javascript native type. Uses a very fast filter function.

Install with npm

npm i filter-type --save

Usage

var filter = require('filter-type');
filter(array, type);

Params

  • array The array to filter
  • type Native JavaScript type to filter by (e.g. string, function etc)

Examples

var arr = [1, 'a', {aaa: 'bbb'}, 3, 'b', 'c', 7, ['foo', 'bar'], function one(){}];

filter(arr, 'object');
//=> [{aaa: 'bbb'}]

filter(arr, 'array');
//=> [['foo', 'bar']]

filter(arr, 'number');
//=> [1, 3, 7]

filter(arr, 'string');
//=> ['a', 'b', 'c']

filter(arr, 'function');
//=> [function one(){}]

Related projects

  • arr-filter: Faster alternative to javascript's native filter method.
  • arr-map: Faster, node.js focused alternative to JavaScript's native array map.
  • arr-flatten: Recursively flatten an array or arrays. This is the fastest implementation of array flatten.
  • filter-types: Filter items from an array or arguments that match the specified javascript native type or… more

Running tests

Install dev dependencies:

npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Jon Schlinkert

License

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


This file was generated by verb-cli on May 02, 2015.[assemble]: http://assemble.io [template]: https://github.com/jonschlinkert/template [verb]: https://github.com/assemble/verb

About

Filter an array or arguments by JavaScript native type (e.g. functions, strings, etc).

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages