difference between find and filter javascript

Solutions on MaxInterview for difference between find and filter javascript by the best coders in the world

showing results for - "difference between find and filter javascript"
Claudia
14 Sep 2018
1//find method returns the first element in an array which meets
2//															a condition
3let numbers = [-1,-2,-4,-6,0,1,2,3,4,5];
4const greaterThanZero = (val) => val > 0;
5numbers.find(greaterThanZero); 
6//Expected output 
7//1
8
9//filter returns an array of elements that meet a condition
10numbers.filter(greaterThanZero);
11//Exected output
12//[1,2,3,4,5]