-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjects.js
More file actions
47 lines (43 loc) · 1.18 KB
/
objects.js
File metadata and controls
47 lines (43 loc) · 1.18 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
let x = { };
let sandwich = {
slices_of_bread: 2,
ham: true,
veggies: ['lettuce', 'tomato', 'onion']
};
console.log(sandwich);
// logging the entire sandwich and all its properties
console.log(sandwich.slices_of_bread);
// examining the 'slices_of_bread' property
console.log(sandwich.veggies[0]);
// logging the first element of the array stored within the veggies property
let sandwiches = [
{
id: 1,
bread_type: 'Sourdough',
ingredients: 'Spicy Turkey, Spicy Mustard'
},
{
id: 2,
bread_type: 'Marbled Rye',
ingredients: 'Prosciutto, Swiss Cheese'
},
{
id: 3,
bread_type: 'Wheat',
ingredients: 'Ham, Provolone Cheese, Tomato'
}
];
// here is an object literal with four key-value pairs
let sandwich = {
cheese: 'Smoked Gouda',
meat: 'Dry-aged Bison',
sauce: 'Chipotle Aioli',
veggies: 'Caramelized Onions'
}
// the variable 'topping' is used instead of an index
for(let topping in sandwich){
// when we log 'topping', we notice it's a key
console.log(topping);
// when we pass the key to the 'sandwich' object, we can pull values
console.log(sandwich[topping]);
}