Describing the filter Operation
filteris used for filtering an array based on a condition-
It accepts a callback function with the following arguments:
currentValue:Current element processed in the arrayindex: Optional index ofcurrentValuearray: Optional array that is calledthisArg: Optional value to use asthis
Defining an Array
let fruits = ["Apple", "Banana"];
console.log(fruits.length);
// 2Using the filter Operation
// Regular function
fruits.filter(function(item, index, array) {
return item.length > 5;
})
// Array["Banana"]
// Arrow function
fruits.filter(item => item.length > 5);
// Array["Banana"]Previous
Next