Answers for "difference between find and filter javascript"

1

difference between find and filter javascript

//find method returns the first element in an array which meets
//															a condition
let numbers = [-1,-2,-4,-6,0,1,2,3,4,5];
const greaterThanZero = (val) => val > 0;
numbers.find(greaterThanZero); 
//Expected output 
//1

//filter returns an array of elements that meet a condition
numbers.filter(greaterThanZero);
//Exected output
//[1,2,3,4,5]
Posted by: Guest on August-01-2021

Code answers related to "difference between find and filter javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language