Javascript | Array Map ES6

CodeyMaze
2 min readApr 10, 2023

--

The map() function is a built-in array method in JavaScript that applies a provided callback function to each element of an array, and returns a new array with the results.

The syntax of the map() method is as follows:

  • callback: Function to execute on each element in the array. It takes three arguments:
  • currentValue: The current element being processed in the array.
  • index (optional): The index of the current element being processed in the array.
  • array (optional): The array map was called upon.
  • thisArg (optional): Object to use as this when executing callback.

Here is an example of how to use the map() method:

In the above example, we are calling the map() method on the numbers array and passing an arrow function as the argument. The arrow function takes one parameter number which represents each element in the array. The arrow function returns the doubled value of each element, and the map() method returns a new array with the doubled values.

In the above example, we are calling the map() method on the persons array and passing an arrow function as the argument. The arrow function takes one parameter person which represents each element in the array. The arrow function returns the name property of each object, and the map() method returns a new array with the names of each person.

--

--

CodeyMaze
CodeyMaze

Written by CodeyMaze

Crafting Solutions Through Code & Words https://codeymaze.com Feel free to follow me :)

No responses yet