19.
What will be the output of the following code?
const numbers = [1, 2, 3, 4, 5];
const filteredNumbers = numbers.filter(function(number) {
return number > 2;
});
console.log(filteredNumbers);
[1, 2, 3, 4, 5]
[3, 4, 5]
[2, 3, 4, 5]
[1, 2]
Correct: B
The filter() method creates a new array with all elements that pass the test implemented by the provided function. In this code, the provided function filters out numbers that are not greater than 2. Therefore, the output will be [3, 4, 5].