-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
75 lines (66 loc) · 1.25 KB
/
app.js
File metadata and controls
75 lines (66 loc) · 1.25 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
function objectsRecap() {
const personOne = {
name: "John",
age: 30,
address: {
street: "123 Main St",
city: "Anytown",
state: "CA",
zip: "12345"
}
};
console.log(personOne);
const personTwo = new Object();
personTwo.name = "John";
personTwo.age = 30;
personTwo.address = {
street: "123 Main St",
city: "Anytown",
state: "CA",
zip: "12345"
};
console.log(personTwo);
const myObj = {
1: 'one',
2.5: 'two',
3: 'three'
};
console.log(myObj['1']); // outputs 'one'
console.log(myObj[2.5]); // outputs 'two'
console.log(myObj[3]); // outputs 'three'
}
function spreadOperator() {
const person = {
name: 'John',
age: 30,
address: {
street: '123 Main St',
city: 'New York',
state: 'NY'
}
};
const newPerson = {
...person,
age: 31,
address: {
...person.address,
city: 'Los Angeles'
}
};
console.log(newPerson);
const p = {
name: "John",
age: 39,
hobbies: [
"singing",
"cooking",
"traveling"
]
}
const newP = {...p, age:30};
console.log(newP); // {name: 'John', age: 30, hobbies: Array(3)}
const newP1 = {...p, hobbies: [...p.hobbies]};
console.log(newP1); // {name: 'John', age: 39, hobbies: Array(3)}
}
// objectsRecap();
spreadOperator();