-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15_Objects_inside_Object.js
More file actions
78 lines (57 loc) · 1.46 KB
/
15_Objects_inside_Object.js
File metadata and controls
78 lines (57 loc) · 1.46 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
// Object inside the object
const User = {
UserId : 123,
Fullname : {
FirstName : "Tarun",
MiddleName : null ,
LastName : "Sharma",
}
}
console.log(User.UserId)
console.log(User.Fullname)
console.log(User.Fullname.LastName)
// 1} adding two oobjects
const obj1 = {
name : "Tarun"
}
const obj2 = {
surname : "Sharma",
age : 22
}
const obj3 ={
category : "general"
}
// Method 1
const resultant = { obj1 , obj2}
console.log(resultant)
// Method 2 <<<<< ASSIGN keyword >>>>>
const target = Object.assign({},obj1, obj2,obj3) // here {} is a target and all other are sources
console.log(target)
// Method 3 {Best Way}
const result = {...obj1,...obj2,...obj3}
console.log(result)
// 2} Object inside the array
const Users = [
{
id : 1,
name : "tarun"
},
{
id : 2,
name : "sahil"
},
{
id : 3,
name : "mandy"
}
]
console.log(Users[1])
console.log(Users[0].name)
// 3} Getting all the keys of the object .
console.log(Object.keys(User)) // all keys will apperas in the form of array.
// 4} Similarly getting only all the values of object.
console.log(Object.values(User)) // all values will also apperas in the form of array.
// 5} Getting all values and keys as separate array inside the array
console.log(Object.entries(User))
// 6} Checking for a key in object <<<<hasOwnProperty>>>
console.log(User.hasOwnProperty("isLoggedIn")) // give boolean result