-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// the object allColors has 3 properties, "red", "green", and "blue" | ||
// each property contains an object with 2 properties, "title" and "hexcode" | ||
var allColors = { | ||
red: { | ||
title: "Red as in Crimson", | ||
hexcode: "#ff0000" | ||
}, | ||
green: { | ||
title: "Green as in Kale", | ||
hexcode: "#00ff00" | ||
}, | ||
blue: { | ||
title: "Blue as in Sky", | ||
hexcode: "#0000ff" | ||
}, | ||
}; | ||
|
||
console.log("The object containing all the color objects:"); | ||
console.log(allColors); // outputs the entire object | ||
|
||
// when the name of the property is a string, use the dot (.) syntax | ||
console.log(allColors.blue); // outputs the object associated with the property "blue" | ||
|
||
// when the property name is the value of a variable, use square brackets, [] | ||
var color = "red"; | ||
|
||
var chosenColorObject = allColors[color]; | ||
|
||
console.log("The object with the property name, " + color + ":"); | ||
console.log(chosenColorObject); // outputs the object associated with the property "red" |