freeCodeCamp Challenge Guide: Accessing Objects Properties with Bracket Notation

freeCodeCamp Challenge Guide: Accessing Objects Properties with Bracket Notation
0

#1

The second way to access the properties of an object is bracket notation ([]). If the property of the object you are trying to access has a space in it, you will need to use bracket notation.

Here is a sample of using bracket notation to read an object property:

var myObj = {
  "Space Name": "Kirk",
  "More Space": "Spock"
};
myObj["Space Name"]; // Kirk
myObj['More Space']; // Spock

Note that property names with spaces in them must be in quotes (single or double).


#3

finally figured it out:

// Setup
var testObj = {
“an entree”: “hamburger”,
“my side”: “veggies”,
“the drink”: “water”
};

// Only change code below this line

var entreeValue = testObj[“an entree”]; // Change this line
var drinkValue = testObj[“the drink”]; // Change this line