-
Notifications
You must be signed in to change notification settings - Fork 0
/
objectsplay.js
40 lines (30 loc) · 914 Bytes
/
objectsplay.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
//Use an array inside an object
const adventurer = {
name: "Timothy",
hitpoints: 10,
belongings: ["sword", "potion", "Tums"],
companion: {
name: "Velma",
type: "Bat",
companion: {
name: "Tim",
type: "Parasite",
belongings: ["SCUBA tank", "Rogan josh", "health insurance"],
},
},
};
// console.log(adventurer.belongings[2]);
// Iterate over an array that is within an object
for (i = 0; i < adventurer.belongings.length; i++) {
console.log(adventurer.belongings[i]);
}
console.log(adventurer.companion.type);
console.log(adventurer.companion.companion.type);
console.log(adventurer.companion.companion.belongings[2]);
// ===== Use an array of objects
const movies = [{ title: "Tokyo Story" }, { title: "Paul Blart: Mall Cop" }];
console.log(movies[0]);
console.log(movies[0].title);
for (let i = 0; i < movies.length; i++) {
console.log(movies[i].title);
}