1var words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
2
3const result = words.filter(word => word.length > 6);
4
5console.log(result);
1const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
2
3const filter = arr.filter((number) => number > 5);
4console.log(filter); // [6, 7, 8, 9]
5
6or
7
8const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
9
10const result = words.filter(word => word.length > 6);
11
12console.log(result);
13// expected output: Array ["exuberant", "destruction", "present"]
1const filtered = array.filter(item => {
2 return item < 20;
3});
4// An example that will loop through an array
5// and create a new array containing only items that
6// are less than 20. If array is [13, 65, 101, 19],
7// the returned array in filtered will be [13, 19]
1var numbers = [1, 3, 6, 8, 11];
2
3var lucky = numbers.filter(function(number) {
4 return number > 7;
5});
6
7// [ 8, 11 ]
1const rebels = pilots.filter(pilot => pilot.faction === "Rebels");
2const empire = pilots.filter(pilot => pilot.faction === "Empire");