Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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]
 
PREVIOUS NEXT
Tagged: #difference #find #filter #javascript
ADD COMMENT
Topic
Name
2+5 =