JavaScript: `filter()` method
.filter() is a built-in array method that is used to filter out the elements of an array based on specific condition.
\=============================================================
The filter method calls a callback
function on each element of array on all indexes. The function need to return a boolean
value true
or false
based on certain conditions. Based on which the function decides whether to include the certain element or not.
The callback
function creates new array
with all elements for which the function returns the condition as true
, and elements for which the function returns condition as false
are simply ommitted out and not included in the new array
that is created.
For Example:
In this example, we have array of studentsParticipating
, We want to delete studentsStepDown
from array and output the filtered array without studentsStepDown
.
Now, let's say we have an more than one student stepping Down, so now we have studentsStepDown
array, we need to remove it's elements from studentsParticipating
and return in new array LatestStudentsParticipating
.
Thanks for reading