Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

indexed-filter

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

indexed-filter

Array#filter with also detecting indexes of filtered values

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

indexed-filter

NPM version Bower version Build Status Coverage Status devDependency Status

Array#filter with also detecting indexes of filtered values

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

Package managers

npm
npm install indexed-filter
Bower
bower install indexed-filter

Standalone

Download the script file directly.

API

indexedFilter(array, filterFn [, thisObject])

array: Array
filterFn: Function
thisObject: (Any value)
Return: Array

The API is vely similar to ECMAScript's built-in 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) and value (array element).
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

Copyright (c) 2015 Shinnosuke Watanabe

Licensed under the MIT License.

Keywords

FAQs

Package last updated on 13 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc