-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmappingArray.html
90 lines (79 loc) · 1.86 KB
/
mappingArray.html
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mapping Array</title>
</head>
<body>
<div id="wrapper">
</div>
<script>
const data = [
{
"name": {
"title": "Mr",
"first": "Levent",
"last": "Busser"
},
"dob": {
"date": "1971-08-21T01:08:00.099Z",
"age": 51
}
},
{
"name": {
"title": "Mr",
"first": "Kornelius",
"last": "Hamnes"
},
"dob": {
"date": "1961-09-23T13:13:49.283Z",
"age": 61
}
},
{
"name": {
"title": "Mademoiselle",
"first": "Ute",
"last": "Henry"
},
"dob": {
"date": "1956-06-30T11:33:42.549Z",
"age": 66
}
},
{
"name": {
"title": "Mr",
"first": "Estéfano",
"last": "Monteiro"
},
"dob": {
"date": "1945-07-16T19:48:22.796Z",
"age": 77
}
}
]
// Write a function that maps through the current data and returns
// a new an array of objects with only two properties:
// fullName and birthday.Each result in your
// array should look like this when you're done:
// {
// fullName: "Levent Busser",
// birthday: "Fri Aug 20 1971"
// }
// Read about toDateString() for info on formatting a readable date.
function transformData(data){
return data.map((current) => {
const obj = {}
obj["fullname"] = current.name.first + " " + current.name.last
obj["birthday"] = new Date(current.dob.date).toDateString()
return obj
})
}
console.log(transformData(data));
</script>
</body>
</html>