-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04_object.js
More file actions
82 lines (52 loc) · 1.75 KB
/
04_object.js
File metadata and controls
82 lines (52 loc) · 1.75 KB
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
// const tinderUser=new Object() //Singleton Object
const tinderUser={} // Non-Singleton Object
tinderUser.id='3ef232'
tinderUser.name="Gabrel"
tinderUser.isLoggedIn=false;
// console.log(tinderUser);
const regularUser={
email:"random@gmail.com",
fullname:{
userfullname:{
firstname:"Raj",
lastname:"Shekhar"
}
}
}
console.log(regularUser.fullname.userfullname.firstname);
const obj1={1:"a",2:"b"}
const obj2={3:"a",4:"b"}
//Object.assign is used to merge two objects
// const obj3=Object.assign(obj1,obj2) //Method 1 using assign
// const obj3=Object.assign({},obj1,obj2) // **more important **,Method 2 using assgin
const obj3={...obj1,...obj2} // 90% (mostly) used, spread method is most widely used to join two or more objects
// console.log(obj3);
console.log(tinderUser);
//Object.keys is used to find the keys in an object
console.log(Object.keys(tinderUser));
//Object.values is used to find the values in an object
console.log(Object.values(tinderUser));
//Object.entries-->Returns an array of key/values of the enumerable properties of an object
console.log(Object.entries(tinderUser));
// Object.hasOwnProperty--> Determines whether an object has a property with the specified name
console.log(tinderUser.hasOwnProperty('isLoggedIn'));
///***************************OBJECT de-Structure and JSON API intro */
const player={
playername:"Raj Shekhar",
teamname:"SuperStrikers",
position:"forward"
}
//another method to access the vcalue of object
const{playername}=player
console.log(playername);
//******* JSON --> JavaScript Object Notation*/
// {
// "name":"Raj Shekhar",
// "coursename":"js in hindi",
// "price":"free"
// }
[
{},
{},
{},
]