DEV Community

Cover image for Critical Examination of filter() Array Method in JavaScript
Kater Akeren
Kater Akeren

Posted on • Edited on

Critical Examination of filter() Array Method in JavaScript

filter() calls a provided callback function once for each element in an array and constructs a new array of all the values for which callback returns a value that coerces to true. In other words filter() creates a new array under a given condition from an existing array.

The Syntax

Alt Text

Example using an array of integers

Alt Text

Filtering an Array of Objects

The very common use case of filter() is with an array of objects through their properties
Alt Text

Top comments (0)