-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjects.js
86 lines (65 loc) · 1.54 KB
/
objects.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
// obejcts are similar to arrays except that instead of index to access the data/element
// we will access data through properties
// object declaration and assignment
var dog = {
name: "Huskey",
legs: 4,
tails: 1,
enemies: ["strayDogs", "Medicine"],
};
// fetching the data using .notation
console.log(dog.name);
//fetching data from object using square brackets
// console.log(dog["eyes"]);
// updating Object Properties
dog.name = "pamorine";
dog["name"] = "vodafoneDog";
console.log(dog.name);
// adding new properties to object
dog.eyes = 2;
dog["eyes"] = 4;
//delete properties in the object
// delete dog.eyes;
delete dog["eyes"];
console.log(dog);
// built in function hasOwnProperty()
console.log(dog.hasOwnProperty("tailsasda"));
var ourMusic = [
{
artist: "Daft Punk",
title: "Homework",
release_year: 1997,
formats: [{ types: ["CD", "DISK"] }],
bronze: true,
details: { firstName: "Daft", lastName: "Punk" },
},
{
artist: "Subhakshmi Concert",
title: "Classical ",
release_year: 1997,
formats: ["CD", "Cassette", "LP"],
platinum: true,
},
{
artist: "Balasubramanyam",
title: "Melody ",
release_year: 1997,
formats: ["CD", "Cassette", "LP"],
Gold: true,
},
];
console.log(ourMusic[0].formats[0].types[1]);
//nested objects
var ourStorage = {
desk: {
drawer: "stapler",
},
cabinet: {
"top drawer": {
folder1: "a file",
folder2: "secrets",
},
"bottom drawer": "soda",
},
};
console.log(ourStorage.cabinet["top drawer"].folder2);