Let the following object be given:
let obj = {
'de': ['mo', 'di', 'mi', 'do', 'fr', 'sa', 'so'],
'en': ['mo', 'tu', 'we', 'th', 'fr', 'sa', 'su'],
};
Let's output some element from our object,
for example, the element 'do'
:
let obj = {
'de': ['mo', 'di', 'mi', 'do', 'fr', 'sa', 'so'],
'en': ['mo', 'tu', 'we', 'th', 'fr', 'sa', 'su'],
};
console.log(obj['de'][3]);
Let now the language and day number are stored in variables:
let lang = 'de';
let day = 3;
Let's use our variables to display some day of the week:
let obj = {
'de': ['mo', 'di', 'mi', 'do', 'fr', 'sa', 'so'],
'en': ['mo', 'tu', 'we', 'th', 'fr', 'sa', 'su'],
};
let lang = 'de';
let day = 3;
console.log(obj[lang][day]);
Given the following object with month names:
let months = {
'de': [
'januar',
'februar',
'marz',
'april',
'mai',
'juni',
'juli',
'august',
'september',
'oktober',
'november',
'dezember',
],
'en': [
'january',
'february',
'march',
'april',
'may',
'june',
'july',
'august',
'september',
'october',
'november',
'december',
],
};
The following variables are also given:
let lang = 'de'; // can be either 'de' or 'en'
let month = 5; // number from 0 to 11
Display the name of the month corresponding
to the values of the variables
lang
and month
.
Here is such a structure for storing a to-do list for years, months and days:
let affairs = {
'2018': {
11: {
29: ['task111', 'task112', 'task113'],
30: ['task121', 'task122', 'task123'],
},
12: {
30: ['task211', 'task212', 'task213'],
31: ['task221', 'task222', 'task223'],
},
},
'2019': {
12: {
29: ['task311', 'task312', 'task313'],
30: ['task321', 'task322', 'task323'],
31: ['task331', 'task332', 'task333'],
}
},
}
Let also be given three variables containing the year, month and day. Output the task corresponding to the values of the variables.
The author of the following code wanted to
output an element with the value '24'
:
let obj = {
key1: {
key2: '12',
key3: '13',
},
key2: {
key4: '24',
key5: '25',
},
}
let key1 = 'key2';
let key2 = 'key4';
console.log(obj['key1'][key2]);
The code, however, doesn't output what the author expected. Fix the error.
The author of the following code wanted to
output an element with the value '24'
:
let obj = {
key1: {
key2: '12',
key3: '13',
},
key2: {
key4: '24',
key5: '25',
},
}
let key1 = 'key2';
let key2 = 'key4';
console.log(obj.key1.key2);
The code, however, doesn't output what the author expected. Fix the error.
The author of the following code wanted to
output an element with the value '24'
:
let obj = {
key1: {
key2: '12',
key3: '13',
},
key2: {
key4: '24',
key5: '25',
},
}
let key1 = 'key2';
let key2 = 'key4';
console.log(obj.key1['key2']);
The code, however, doesn't output what the author expected. Fix the error.
The author of the following code wanted to
output an element with the value '24'
:
let obj = {
key1: {
key2: '12',
key3: '13',
},
key2: {
key4: '24',
key5: '25',
},
}
let key1 = 'key2';
console.log(obj['key1']['key4']);
The code, however, doesn't output what the author expected. Fix the error.