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

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

a) To create a new array by transforming every element in an array
b) To filter out elements from an array
c) To find the index of an element in an array
d) To modify the original array

Answer:

a) To create a new array by transforming every element in an array

Explanation:

The Array.map() method creates a new array populated with the results of calling a provided function on every element in the original array. The original array remains unchanged.

This method is often used for transforming data in a clean and concise way.

Reference:

JavaScript MCQ (Multiple-Choice Questions)

Leave a Comment

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

Scroll to Top