What is the purpose of the Array.filter() method in JavaScript?

What is the purpose of the Array.filter() method in JavaScript?

a) To create a new array with elements that pass a test
b) To remove elements from the original array
c) To apply a function to every element of an array
d) To sort the elements of an array

Answer:

a) To create a new array with elements that pass a test

Explanation:

The Array.filter() method creates a new array with all elements that pass the test implemented by the provided function. It doesn’t modify the original array.

Reference:

JavaScript MCQ (Multiple-Choice Questions)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top