The .map() function will go through the entire array, and on each step of that process it will take the current item that we are looking at and will pass it as a parameter into the function. You can then do whatever you want to that item, and whatever you return from your function will replace what is in that position in the array.

Say for example, with the array you gave in your question, we wanted to remove the name and last_name properties, and combine them into a full_name property. We can do the following:

 let people = [
   {
     id: 1,
     name: 'jhon',
     last_name: 'wilson'
   },
   {
     id: 2,
     name: 'maria',
     last_name: 'anyway'
   },
     id: 3,
     name: 'lastOne',
     last_name: 'example'
   }
];

people = people.map((person) => {
  return {
    id: person.id,
    full_name: `${person.name} ${person.last_name}`
  }
});

After this code runs, our people array would look like this:

[
   {
     id: 1,
     full_name: 'jhon wilson'
   },
   {
     id: 2,
     full_name: 'maria anyway'
   },
     id: 3,
     name: 'lastOne example'
   }
];

You can think of it as doing something very similar to this:

function transformPerson(person) {
  return {
    id: person.id,
    full_name: `${person.name} ${person.last_name}`
  }
}

let newPeople = [];
for (let i = 0; i < people.length; i++) {
  newPeople[i] = transformPerson(people[i])
}

people = newPeople;
Answer from Ashley on Stack Overflow
🌐
W3Schools
w3schools.com › jsref › jsref_map.asp
JavaScript Array map() Method
❮ Previous JavaScript Array Reference Next ❯ · Return a new array with the square root of all element values: const numbers = [4, 9, 16, 25]; const newArr = numbers.map(Math.sqrt) Try it Yourself » · Multiply all the values in an array with 10: const numbers = [65, 44, 12, 4]; const newArr = numbers.map(myFunction) function myFunction(num) { return num * 10; } Try it Yourself » · More examples below.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › map
Array.prototype.map() - JavaScript - MDN Web Docs
July 12, 2026 - A new array with each element being the result of the callback function. The map() method is an iterative method. It calls a provided callbackFn function once for each element in an array and constructs a new array from the results.
Discussions

javascript - transform an array of objects with map( ) - Stack Overflow
I can't understand how the map () method works because all the examples are with numbers and to understand I need an example with something more specific. so I made this I have an array of objects:... More on stackoverflow.com
🌐 stackoverflow.com
Difference between Map and map?
Whatever problem/project you’re doing, 99% chance they mean array.prototype.map(), which will return a new array where the callback you provide will be called on every element in the array. More on reddit.com
🌐 r/learnjavascript
24
50
July 26, 2022
When to use Arrays / Objects / Maps
In my experience maps are not used that often in day-to-day JS programming. Most of the time you're dealing with fairly simple key-value data structures that are easily represented by objects, and where you benefit from the very simple translation directly to and from JSON. Maps can be useful where converting to/from JSON is not really a concern and your code can benefit from the fact that anything can be the key in a map (in a standard JS object keys can only be strings or symbols). So you could associate an object, or a function, or really anything, with any other value by using a map. As a beginner I really wouldn't worry that much about maps. There are a lot of features in JS- or any other programming language- that are very useful when you need them but also fairly niche, and that you are unlikely to use very often. More on reddit.com
🌐 r/learnjavascript
3
1
January 20, 2023
What is this underscore: [...Array(5)].map((_,x) => x++);
_ is often used as a throwaway variable. In other words, just ignore it. It's the same thing as this: [...Array(5)].map((unused, x) => x++); Also, you don't need to x++, just x would do. More on reddit.com
🌐 r/javascript
23
5
March 29, 2018
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-array-map-method
JavaScript Array map() Method - GeeksforGeeks
June 1, 2026 - Example 2: This example uses the array map() method and returns the square of the array element.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Map
Map - JavaScript - MDN Web Docs - Mozilla
August 13, 2026 - The following are examples of read-only Map-like browser objects: ... Creates a new Map object. ... The constructor function that is used to create derived objects. ... Groups the elements of a given iterable using the values returned by a provided callback function. The final returned Map uses the unique values from the test function as keys, which can be used to get the array of elements in each group.
🌐
DigitalOcean
digitalocean.com › community › tutorials › 4-uses-of-javascripts-arraymap-you-should-know
How to Use the JavaScript .map() Method | DigitalOcean
Learn how to use the JavaScript .map() method to transform arrays with clear examples, syntax explanations, and practical use cases.
🌐
freeCodeCamp
freecodecamp.org › news › javascript-map-how-to-use-the-js-map-function-array-method
JavaScript Map – How to Use the JS .map() Function (Array Method)
March 31, 2021 - The callback function() is called on each array element, and the map() method always passes the current element, the index of the current element, and the whole array object to it. The this argument will be used inside the callback function. By default, its value is undefined . For example, here's how to change the this value to the number 80:
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript array methods › array.prototype.map()
JavaScript Array map() Method
November 8, 2024 - Summary: in this tutorial, you will learn how to use the JavaScript Array map() method to create a new array by applying a function to every element in the original array.
Find elsewhere
🌐
Programiz
programiz.com › javascript › library › array › map
JavaScript Array map()
... let newPrices = prices.map(Math.sqrt); // [ 42.42640687119285, 44.721359549995796, 54.772255750516614, // 70.71067811865476, 22.360679774997898, 89.44271909999159 ] console.log(newPrices); // custom arrow function const string = "JavaScript"; const stringArr = string.split(''); // array ...
🌐
Mimo
mimo.org › glossary › javascript › map
JavaScript Map Function: Examples for Data Transformation
The .map() method creates a new array by calling a provided function on every element in the original array. It takes each element, transforms it according to the function, and adds the result to the new array. The original array remains unchanged. ... Become a full-stack developer. Learn HTML, CSS, JavaScript, and React as well as NodeJS, Express, and SQL
Top answer
1 of 3
2

The .map() function will go through the entire array, and on each step of that process it will take the current item that we are looking at and will pass it as a parameter into the function. You can then do whatever you want to that item, and whatever you return from your function will replace what is in that position in the array.

Say for example, with the array you gave in your question, we wanted to remove the name and last_name properties, and combine them into a full_name property. We can do the following:

 let people = [
   {
     id: 1,
     name: 'jhon',
     last_name: 'wilson'
   },
   {
     id: 2,
     name: 'maria',
     last_name: 'anyway'
   },
     id: 3,
     name: 'lastOne',
     last_name: 'example'
   }
];

people = people.map((person) => {
  return {
    id: person.id,
    full_name: `${person.name} ${person.last_name}`
  }
});

After this code runs, our people array would look like this:

[
   {
     id: 1,
     full_name: 'jhon wilson'
   },
   {
     id: 2,
     full_name: 'maria anyway'
   },
     id: 3,
     name: 'lastOne example'
   }
];

You can think of it as doing something very similar to this:

function transformPerson(person) {
  return {
    id: person.id,
    full_name: `${person.name} ${person.last_name}`
  }
}

let newPeople = [];
for (let i = 0; i < people.length; i++) {
  newPeople[i] = transformPerson(people[i])
}

people = newPeople;
2 of 3
0

Array.map() takes in a function as a parameter, passes each item of the array into the function, and returns an array of the result.

For example, if I wanted to multiply each of the items in the array by 2:

const x = [1, 2, 3, 4, 5]
const y = x.map(v => v * 2) // result: [2, 4, 6, 8, 10]

Note: Array.map does not affect the original array; it creates a new array of the results.

🌐
CodeSweetly
codesweetly.com › javascript-map-method
map() JavaScript Array Method – Explained with Examples | CodeSweetly
In the example above, myName is the calling array. Section titled “Example 2: map() with a thisValue Argument”
🌐
Hostman
hostman.com › tutorials › how-to-use-javascript-array-map
How to Use JavaScript Array map(): A Comprehensive Guide
This function runs once for every item in the array. Importantly, map() does not modify the original array; instead, it returns a new array with the transformed elements. For example, if you have an array of numbers and want to add 1 to each number, you can use map() like this:
🌐
Tabnine
tabnine.com › home › how to use the array map() method in javascript
How to Use The Array map() Method in JavaScript - Tabnine
July 25, 2024 - Using map() allows us to iterate ... returned to us inside a new array. For example, the following code iterates through an array of numbers and multiplies each number by 2:...
🌐
TutorialsPoint
tutorialspoint.com › javascript › array_map.htm
JavaScript - Array map() Method
This method returns a new array ... following example, we are passing a multiplication function as a callback function to the map() method, where it multiplies all the array elements with number 10....
🌐
freeCodeCamp
freecodecamp.org › news › array-map-tutorial
JavaScript Array.map() Tutorial – How to Iterate Through Elements in an Array with map()
October 15, 2024 - On one end, there is an array (A) you want to operate on. map() takes in all elements in that array (A), performs a consistent action on each of those elements, and returns them into a new array (B). To illustrate how map() works in JavaScript, ...
🌐
Linode
linode.com › docs › guides › how-to-use-javascript-map-function
How to Use the JavaScript Map() Function to Transform Arrays | Linode Docs
April 3, 2023 - The example below processes an array representing a queue of customers. For each person, the map() function generates a new string combining their last and first names along with their position in the queue: Executing the JavaScript code above results in the following output:
🌐
Ultimate Courses
ultimatecourses.com › blog › array-map-javascript
Exploring Array Map in JavaScript - Ultimate Courses
Think of Array Map as: “I want a new array containing new copies, or changes, of each array element” · You could, for example, use Map to return a specific property from an object, which would result in an array of just those properties ...
🌐
Robin Wieruch
robinwieruch.de › javascript-map-array
Deep Dive into JavaScript's Array Map Method - Robin Wieruch
March 6, 2019 - A common example might be if you have an object where each key represents a unique id, but all of the values might be a similar type (sort of like a JavaScript Set). While map won’t work directly on objects, we can use map to transform all ...
🌐
Dev Handbook
devhandbook.com › dev handbook › javascript › javascript arrays › how to use .map() to iterate through array items
How to use .map() to iterate through array items | Dev Handbook
June 15, 2026 - const newArray = array.map((currentElement, index, array) => { return /* transformed value */; }); ... const numbers = [1, 2, 3, 4]; const doubled = numbers.map(n => n * 2); console.log(doubled); // [2, 4, 6, 8] console.log(numbers); // [1, ...
🌐
Hackr
hackr.io › home › articles › programming
Beginner’s Guide to JavaScript Map Array | Array Map() Method
January 30, 2025 - The JavaScript array.map() method creates a new array of elements that are the result of calling a provided callback function on every element in the calling array.