# Functional Programming - Use the map Method to Extract Data from an Array

**URL:** <https://forum.freecodecamp.org/t/functional-programming-use-the-map-method-to-extract-data-from-an-array/600412>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [March 24, 2023, 9:29am UTC](https://forum.freecodecamp.org/t/functional-programming-use-the-map-method-to-extract-data-from-an-array/600412 "2023-03-24T09:29:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rishuldpadhiar](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/rishuldpadhiar/32/307688_2.png) [@rishuldpadhiar](https://forum.freecodecamp.org/u/rishuldpadhiar)\
**Post date:** [March 24, 2023, 9:29am UTC](https://forum.freecodecamp.org/t/functional-programming-use-the-map-method-to-extract-data-from-an-array/600412/1 "2023-03-24T09:29:04Z")

</div>

Hi all, thanks for taking the time to look at my question 🙂

I’m having a bit of trouble understanding this function in the example, so i understand that the map function will iterate over users to extract the results i want.

But what i dont understand is (user =\> user.name), why dont we have just name? How would i read the contents inside the brackets (user =\> user.name),

```auto
const users = [
  { name: 'John', age: 34 },
  { name: 'Amy', age: 20 },
  { name: 'camperCat', age: 10 }
];

const names = users.map(user => user.name);
console.log(names);

```

The console would display the value `['John', 'Amy', 'camperCat']`

Thanks

---

<div class="post-metadata">

**Author:** ![sanity](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sanity/32/378897_2.png) [@sanity](https://forum.freecodecamp.org/u/sanity)\
**Post date:** [March 24, 2023, 7:31pm UTC](https://forum.freecodecamp.org/t/functional-programming-use-the-map-method-to-extract-data-from-an-array/600412/2 "2023-03-24T19:31:39Z")

</div>

`map` passes each element of the array to the callback function and then uses result from that function.

`user => user.name` is a function written using arrow syntax. It takes single argument named `user`, and returns `user.name`.

Without arrow syntax it could look like this:

```auto
const names = users.map(function (user) {
  return user.name;
});

```

It could use _just name_ when destructuring, but I’m not sure if that’s what you meant.

```auto
const names = users.map(({ name }) => name);

```

```auto
const names = users.map(function ({ name }) {
  return name;
});

```

---

<div class="post-metadata">

**Author:** ![lanceamd](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lanceamd/32/310024_2.png) [@lanceamd](https://forum.freecodecamp.org/u/lanceamd)\
**Post date:** [March 24, 2023, 9:23pm UTC](https://forum.freecodecamp.org/t/functional-programming-use-the-map-method-to-extract-data-from-an-array/600412/3 "2023-03-24T21:23:27Z")

</div>

Just to add to these good responses… the user variable is defined by the function. It could be any vaiable name you like. User is referencing the current elemant of the array and passing it to the function

---

<div class="post-metadata">

**Author:** ![tahmid\_cc](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/tahmid_cc/32/187147_2.png) [@tahmid\_cc](https://forum.freecodecamp.org/u/tahmid_cc)\
**Post date:** [March 24, 2023, 11:14pm UTC](https://forum.freecodecamp.org/t/functional-programming-use-the-map-method-to-extract-data-from-an-array/600412/4 "2023-03-24T23:14:25Z")

</div>

This code generates an array of objects called users, each of which has two properties: a name and an age.  
Finally, a new array called names is created by using the map() method to extract only the name field from each object in the users array. The callback function that is passed as a parameter to the map() method is called once for each user in the users array.  
In this instance, the callback function extracts and returns the name property from each object in the users array using an arrow function.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [September 23, 2023, 11:14am UTC](https://forum.freecodecamp.org/t/functional-programming-use-the-map-method-to-extract-data-from-an-array/600412/5 "2023-09-23T11:14:57Z")

</div>

Closed on September 23, 2023, 11:14am UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
