Get Programming with JavaScript - Listing 10.04
Listing 10.04 - Using Object.keys
JS Bin
var ages = {
"Kandra Smith" : 56,
"Dax Aniaku" : 210,
"Blinky" : 36
};
var keys = Object.keys(ages);
console.log(keys);
Further Adventures
Listing 10.04 - Using Object.keys - Task 1
- Add a couple more key-value pairs to the ages object.
var ages = {
"Kandra Smith" : 56,
"Dax Aniaku" : 210,
"Blinky" : 36,
"Filboid Studge" : 120,
"??? Mr Nigma ???" : 37
};
var keys = Object.keys(ages);
console.log(keys);
Listing 10.04 - Using Object.keys - Task 2
- Add another property to the ages object using square bracket notation.
- Add the code before the call to Object.keys, so the new key will be logged to the console.
var ages = {
"Kandra Smith" : 56,
"Dax Aniaku" : 210,
"Blinky" : 36,
"Filboid Studge" : 120,
"??? Mr Nigma ???" : 37
};
// another property
ages["Yet another property!!!"] = 16;
var keys = Object.keys(ages);
console.log(keys);