liveBook · Manning

Array.prototype.filter

Array.prototype.filter is a JavaScript method that returns a new array containing the elements for which a callback predicate returns a truthy value.

How 2 Manning books explain it

Secrets of the JavaScript Ninja, Second Edition

An Array method that creates a new array containing elements that pass a callback test.

How it is used
Selects all array items matching a callback test, including when constructing a set intersection.
How deep it goes
Explains the new-array result through a worked predicate example; does not detail the callback’s full signature.
Examples
Filters armed ninjas from an array and intersects ninja and samurai sets to retain Hattori.
What you can do after
Apply it via Array.prototype.filter to collect matching array items or help construct a set intersection.

Read how Secrets of the JavaScript Ninja, Second Edition explains Array.prototype.filter →

D3.js in Action, Third Edition

The JavaScript filter() method creates a new array containing the elements that satisfy a callback condition.

How it is used
Selects a subset of data for a visualization, such as employees matching a Boolean property.
How deep it goes
Demonstrates the callback-based operation with an employee dataset, but does not discuss implementation internals or performance.
Examples
Uses an employee array and the works_with_d3 Boolean property to demonstrate selecting matching records.
What you can do after
Apply it via JavaScript to create a new array containing records that satisfy a callback condition.

Read how D3.js in Action, Third Edition explains Array.prototype.filter →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.