-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjectOperations.js
56 lines (40 loc) · 1003 Bytes
/
ObjectOperations.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
//mutable java script
const obj={
a:2,
b:3,
h:11,
};
obj.d=33;
console.log(obj);
//traversing
//immutable java script
//CRUD(create,read,update,delete) OPERATION USING IMMUTABLE JAVASCRIPT
//OLD JS TECHNIQ
const obj1=Object.assign({},obj,{e:44});
console.log(obj1);
//NEW JS TECHNIQ
//SPREAD OPERATER(...)
// example of add new value in object using immuatablejs
//when you need to add new property dd before spread operater
const obj2={x:10,y:11,...obj};
console.log(obj2);
// update object value using immutable js
//when you need to update new property dd before spread operater
const obj3={...obj,b:2};
const obj4={b:2,...obj};
console.log(obj3);
console.log(obj4);
console.log(obj);
//delete property/propertieswe have to use object destructure
const user={
fName:'Ansh'
}
const{fName:firstName}=user;
console.log(firstName)
const a=1010;
// console.log(obj.a);
// console.log(obj.b);
const {a:abc,b,...rest}=obj;
console.log(a);
console.log(abc);
console.log(rest);