-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path34Object.js
56 lines (43 loc) · 1.17 KB
/
34Object.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
// Objects
// Object is A References Type
// arrays are good but not sufficient
// for real world data
// objects store key values pairs
// objects don't have index
// There are 3 ways to create an object in JavaScript.
// 1). By object literal
// 2). By creating an instance of Object
// 3). By Object Constructor
// Creating An Object
// object #1 key-value pair
// const person = {name:"Abhishek",age:22};
// object #2
// const person = {
// name: "Abhishek",
// age: 22,
// hobbies: ["guitar", "sleeping", "Listening Music"]
// }
// #3 like these we can also use
const person = {
"name": "Abhishek",
"age": 22,
"hobbies": ["guitar", "sleeping", "Listening Music"]
}
console.log(person);
// object name property
// Accessing data from objects
// Accessing objects proprties
// Dot Notation
console.log(person.name);
console.log(person.age);
console.log(person.hobbies);
// Bracket Notation || without Dot notation
console.log(person["name"]);
console.log(person ["age"]);
console.log(person["hobbies"]);
// Adding key value pair to objects
// Dot notation
// person.gender = "male";
// Bracket Notation
person["gender"] = "male";
console.log(person);