forked from Swap76/Learn-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter.js
More file actions
25 lines (19 loc) · 697 Bytes
/
Copy pathfilter.js
File metadata and controls
25 lines (19 loc) · 697 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// JavaScript Array filter() Method
/* The filter() method creates a new array with all elements that
pass the test implemented by the provided function.
*/
const words = ["spray", "limit", "elite", "exuberant", "destruction", "present"];
const result = words.filter(word => word.length > 6);
console.log(result);
// expected output: Array ["exuberant", "destruction", "present"]
/*
Another example
Filtering out all small values
The following example uses filter() to create a filtered array that has all elements
with values less than 10 removed.
*/
function isBigEnough (value) {
return value >= 10;
}
var filtered = [12, 5, 8, 130, 44].filter(isBigEnough);
// filtered is [12, 130, 44]