Filter method in JavaScript
1 min readMay 7, 2022
concise explanation of filter method in Js
The filter() method creates a new array with all elements that pass the condition provided by the callback function.
- Creates a new array.
- Iterates through the given array.
- Runs a callback function on each element of the given array.
- If the callback function returns true, that value will be added to the new array.
- If the callback function returns false, that value will be ignored from the new array.
Note: the result of the callback function always returns a boolean.
How does it work?
Note: learn more about callback function parameters here.
Example:
Write a function to return a new array of all the numbers divisible by three.
Also, Read