forked from jamesqquick/javascript-array-functions-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.js
More file actions
40 lines (39 loc) · 968 Bytes
/
map.js
File metadata and controls
40 lines (39 loc) · 968 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
39
40
const characters = [
{
name: 'Luke Skywalker',
height: 172,
mass: 77,
eye_color: 'blue',
gender: 'male',
},
{
name: 'Darth Vader',
height: 202,
mass: 136,
eye_color: 'yellow',
gender: 'male',
},
{
name: 'Leia Organa',
height: 150,
mass: 49,
eye_color: 'brown',
gender: 'female',
},
{
name: 'Anakin Skywalker',
height: 188,
mass: 84,
eye_color: 'blue',
gender: 'male',
},
];
//***MAP***
//1. Get array of all names
console.log(characters.map(item => item.name))
//2. Get array of all heights
console.log(characters.map(item => item.height))
//3. Get array of objects with just name and height properties
console.log(characters.map(item => `${item.name} is ${item.height} in tall`))
//4. Get array of all first names
console.log(characters.map(item => item.name.split(' ')[0]))