Get Programming with JavaScript - Listing 10.01
Listing 10.01 - Bracket notation for object properties
JS Bin
var ages = {};
ages["Kandra"] = 56;
ages["Dax"] = 21;
console.log(ages.Kandra);
console.log(ages.Dax);
Further Adventures
Listing 10.01 - Bracket notation for object properties - Task 1
- Add a couple more properties to the ages object.
var ages = {};
ages["Kandra"] = 56;
ages["Dax"] = 21;
// add a couple more properties
ages["Jahver"] = 41;
ages["Boo"] = 5;
console.log(ages.Kandra);
console.log(ages.Dax);
Listing 10.01 - Bracket notation for object properties - Task 2
- Change the calls to console.log to use square bracket notation as well.
var ages = {};
ages["Kandra"] = 56;
ages["Dax"] = 21;
ages["Jahver"] = 41;
ages["Boo"] = 5;
// use square bracket notation
console.log(ages["Kandra"]);
console.log(ages["Dax"]);