JS array.filter()

JavaScript has many array methods that can help you solve a variety of problems. One of those methods is the filter() method. The filter() method creates a new array with all of the elements that pass the test implemented by the provided function.

Syntax

array.filter(function(currentValue, index, array), thisValue)

Parameters

A function to be run for each element in the array.
function(currentValue, index, array)

Function arguments:

currentValue

Index

Array

Value

Return Value

The return value is a new array containing the elements that passed the test. If no elements passed the test, the return value will be an empty array.

Examples

Happy coding!

More Info!

JavaScript docs

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store