-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdestructuring.js
61 lines (55 loc) · 1.28 KB
/
destructuring.js
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
var {name, position} = {
name: 'Raunaq',
position: 'Forward',
city: 'Mumbai',
language: 'English'
};
console.log(name, position, '\n')
function returnObj() {
return {
name: 'Raunaq',
position: 'Forward',
city: 'Mumbai',
language: 'English'
};
}
var {name:name1, position:pos1} = returnObj();
console.log(name1, pos1, '\n');
var people = [
{
"firstName": "Clinton",
"lastName": "Ruiz",
"phone": "1-403-985-0449",
"email": "[email protected]",
"address": "Ap #829-3443 Nec St."
},
{
"firstName": "Skyler",
"lastName": "Carroll",
"phone": "1-429-754-5027",
"email": "[email protected]",
"address": "P.O. Box 171, 1135 Feugiat St."
},
{
"firstName": "Kylynn",
"lastName": "Madden",
"phone": "1-637-627-2810",
"email": "[email protected]",
"address": "993-6353 Aliquet, Street"
},
{
"firstName": "Chaney",
"lastName": "Edwards",
"phone": "1-397-181-4501",
"email": "[email protected]",
"address": "P.O. Box 342, 9574 Egestas Street"
}
]
people.forEach(
({firstName}) => console.log(firstName)
);
var [, Skyler] = people; // descructuring of arrays is quite interesting
function logEmail({email}) {
console.log(email);
}
logEmail(Skyler);