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

array-filter

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-filter

Array#filter for older browsers.

  • 0.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5M
increased by21.98%
Maintainers
1
Weekly downloads
 
Created

What is array-filter?

The array-filter npm package provides a simple utility for filtering elements in an array based on a provided callback function. It is a lightweight and straightforward implementation of the Array.prototype.filter method, making it useful for environments where the native method is not available or for those who prefer a minimalistic approach.

What are array-filter's main functionalities?

Basic Filtering

This feature allows you to filter an array of numbers to only include even numbers. The callback function checks if each number is even.

const filter = require('array-filter');
const numbers = [1, 2, 3, 4, 5];
const evenNumbers = filter(numbers, function(number) {
  return number % 2 === 0;
});
console.log(evenNumbers); // [2, 4]

Filtering with Custom Conditions

This feature demonstrates filtering an array of strings to only include words longer than 5 characters. The callback function checks the length of each word.

const filter = require('array-filter');
const words = ['apple', 'banana', 'cherry', 'date'];
const longWords = filter(words, function(word) {
  return word.length > 5;
});
console.log(longWords); // ['banana', 'cherry']

Filtering Objects in an Array

This feature shows how to filter an array of objects to only include those where the age property is 30 or above. The callback function checks the age property of each object.

const filter = require('array-filter');
const people = [
  { name: 'Alice', age: 25 },
  { name: 'Bob', age: 30 },
  { name: 'Charlie', age: 35 }
];
const adults = filter(people, function(person) {
  return person.age >= 30;
});
console.log(adults); // [{ name: 'Bob', age: 30 }, { name: 'Charlie', age: 35 }]

Other packages similar to array-filter

Keywords

FAQs

Package last updated on 22 May 2013

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