Creates a new array with the results of calling a function for every element in array.


array.map((element, index, array) => {...});

The callback function accepts the following parameters:

  • element (required): The current element we are iterating through.
  • index (optional): The index of the current element we are iterating through.
  • array (optional): The array that map() was called on.


Create a new array which doubles the values in numbers:

const numbers = [1, 2, 3, 4, 5];
const doubled = numbers.map((value) => value * 2);
// Output: [2, 4, 6, 8, 10]

Create an array of full names from the students array full of objects:

const students = [
{ first_name: 'Samantha', last_name: 'Jones' },
{ first_name: 'Hector', last_name: 'Gonzales' },
{ first_name: 'Jeremiah', last_name: 'Duncan' },
const fullNames = students.map((student) => {
return `${student.first_name} ${student.last_name}`;
// Output: ['Samantha Jones', 'Hector Gonzales', 'Jeremiah Duncan']


Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn JavaScript on Codecademy