-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathds.js
124 lines (83 loc) · 2.16 KB
/
ds.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//Destructuring assignment
let planets = ["Sun","Moon","Earth"];
//let planet1 = planets[0];
//let planet2 = planets[1];
let [planet1,planet2] = ["Sun","Moon"];
console.log(planet1,planet2);
let [solar1,solar2,solar3] = [planets];
console.log(solar1,solar2,solar3);
//spread operator
const [body1,... rest] = ["Sun","Moon","Earth"];
console.log(body1);
console.log(rest);
let plants = ["Sunflower","Moonflower","Earthflower"];
let ferns = ["ferni","corni","secri"];
//combine two arrays using spread operator
let flora = ["Blossom",...plants,...ferns];
console.log(flora);
//or using concat function ??
//let flora = plants.concat(ferns);
//console.log(flora);
let [first,second] = flora;
console.log(first,second);
let rings = ["Diamond","Sapphire","Gold"];
const price = ["10000$","3000$","7000$"];
const budget= ["Ruby","Titanium",...rings,...price];
const [hold1,...future]=budget;
console.log(future);
// destructuring assignments in object
let student = {
name:"ram",
age: 20
}
console.log(student.name);
//but here...
const {name="Hari",age} = student;
//we can assign a name inside here if the object keys are empty
name;
age;
//giving alias or nickname
let student1 = {
// forname:"Shyam",
name:"shyam",
agein: 21,
location: {
zipcode: 44207,
lattitude: 1,
longitude: 2
}
}
// now only studentName would be shown
const {forname:studentName = //using in case no value
"Sita",agein} = student1;
studentName;
agein;
//using spreading operator
const {forname,...otherdata} = student1;
console.log(otherdata);
//accessing data withing keys
console.log(student1.location.zipcode);
const {location:{zipcode}} = student1;
zipcode;
//assigning
//let a = {}
//Object.assign(a,student1);
//Instead of this , we use spreading operator
let a = {...student1,...student};
//student overrides name
a;
//see it does the job easily 🥳🥳🥳
//deep copy
let tea = {
name:"Tokla",
agein: 21,
location: {
zipcode: 44207,
lattitude: 1,
longitude: 2,
details:{...student1}
}
};
//const {location:{details:{location:{lattitude}}}} = tea;
let c = Object.assign({...student},tea);
c;