Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

What is the filter() method? in Javascript

/* What is the filter() method?
	This method returns all the elements of the array that satisfy the condition
    specified in the callback function.
*/

const x = [1, 2, 3, 4, 5];

const y = x.filter(el => el*2 === 2);

console.log("y is: ", y); // y is: [1]

/* If you check out the output of the above example,
	the value of y is an array of 1 element that satisfies the condition.
    This is because the filter() method iterates over all elements of the array and
    then returns a filtered array which satisfy the condition specified.
*/
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #What #Javascript
ADD COMMENT
Topic
Name
9+7 =