For which purpose the array "map()" methods is used?

For which purpose the array “map()” methods is used?

  1. It used for mapping the elements of another array into itself.
  2. It passes each data-item of the array and returns the necessary mapped elements.
  3. It passes the data-items of an array into another array.
  4. It passes every element of the array on which it is invoked to the function you specify, and returns an array containing the values returned by that function.
1 Like

4th option is correct as map is high order function and used to map each element of container as per condition given.

1 Like

4th option is the correct one. i.e, It passes every element of the array on which it is invoked to the function you specify, and returns an array containing the values returned by that function.

map() Example:

const numbers = [4, 9, 16, 25];
document.getElementById("demo").innerHTML = numbers.map(Math.sqrt);
//Answer:2,3,4,5
2 Likes