-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4.Map.js
More file actions
38 lines (34 loc) · 915 Bytes
/
4.Map.js
File metadata and controls
38 lines (34 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* Author: Marc Ciruelos Santos
* Date: 21-02-2024
* Description: Array map() => Examples using the map() function with an objects array.
*/
const books = [
{
id: 1,
title: "Thinking, fast and slow",
author: "Daniel Kahneman",
price: 12.5,
format: "paperback",
genres: ["Education", "Psychology"],
},
{
id: 2,
title: "Deep work. Rules for focused success in a distracted world",
author: "Cal Newport",
price: 25.69,
format: "hardcover",
genres: ["Education", "Business"],
},
{
id: 3,
title: "Rules for life: An antidote to chaos",
author: "Jordan B. Peterson",
price: 12.86,
format: "paperback",
genres: ["Business", "Study Skills"],
},
];
// Map() --> (as a loop for but declarative). Returns only the selected field.
// Create a new array with only the title of each book.
console.log(books.map((book) => book.title));