2018-10-12 15:37:13 -04:00
---
title: Use the map Method to Extract Data from an Array
---
2019-07-24 00:59:27 -07:00
# Use the map Method to Extract Data from an Array
2018-10-12 15:37:13 -04:00
2019-07-24 00:59:27 -07:00
---
## Hints
### Hint 1
2018-10-12 15:37:13 -04:00
array.prototype.map takes a function as in input and returns an array. The returned array includes elements that is processed by the function. This function takes individual elements as input.
2019-07-24 00:59:27 -07:00
---
## Solutions
2018-10-12 15:37:13 -04:00
2019-07-24 00:59:27 -07:00
< details > < summary > Solution 1 (Click to Show/Hide)< / summary >
2018-10-12 15:37:13 -04:00
```javascript
2019-07-24 00:59:27 -07:00
const rating = watchList.map(item => ({
title: item["Title"],
rating: item["imdbRating"]
}));
2018-10-12 15:37:13 -04:00
```
2019-07-24 00:59:27 -07:00
#### Code Explanation
2018-10-12 15:37:13 -04:00
Using ES6 notation, each item in array is processed to extract title and rating.
Parantheses are needed to return an object.
#### Relevant Links
* < a href = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions' target = '_blank' rel = 'nofollow' > Arrow Functions</ a >
2019-07-24 00:59:27 -07:00
< / details >