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]
1const filterThisArray = ["a","b","c","d","e"]
2console.log(filterThisArray) // Array(5) [ "a","b","c","d","e" ]
3
4const filteredThatArray = filterThisArray.filter((item) => item!=="e")
5console.log(filteredThatArray) // Array(4) [ "a","b","c","d" ]
6
1var numbers = [1, 3, 6, 8, 11];
2
3var lucky = numbers.filter(function(number) {
4 return number > 7;
5});
1 //filter numbers divisible by 2 or any other digit using modulo operator; %
2
3 const figures = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
4 const divisibleByTwo = figures.filter((num) => {
5 return num % 2 === 0;
6 });
7 console.log(divisibleByTwo);