-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13_addKVPairsToJSObjects.js
54 lines (47 loc) · 1.18 KB
/
13_addKVPairsToJSObjects.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
// Add Key-Value Pairs to JavaScript Objects
// Consider the following object:
const tekkenCharacter = {
player: 'Hwoarang',
fightingStyle: 'Tae Kwon Doe',
human: true
};
// now let's add a new key-value pair:
tekkenCharacter.origin = 'South Korea';
console.log(tekkenCharacter);
/*
{
player: 'Hwoarang',
fightingStyle: 'Tae Kwon Doe',
human: true,
origin: 'South Korea'
}
*/
/* Let's add another key-value pair from the value of a
variable (this requires bracket notation): */
const hairColor = 'dyed orange';
tekkenCharacter['hair color'] = hairColor;
console.log(tekkenCharacter);
/*
{
player: 'Hwoarang',
fightingStyle: 'Tae Kwon Doe',
human: true,
origin: 'South Korea',
hair color: 'dyed orange'
}
*/
/* A foods object has been created with three entries. Using
the syntax of your choice, add three more entries to it:
bananas with a value of 13, grapes with a value of 35, and
strawberries with a value of 27. */
let foods = {
apples: 25,
oranges: 32,
plums: 28
};
// Only change code below this line
foods.bananas = 13;
foods['grapes'] = 35;
foods.strawberries = 27;
// Only change code above this line
console.log(foods);