Created
December 17, 2016 22:52
-
-
Save anonymous/d52ec5941a0d4c929256dd62d2865e83 to your computer and use it in GitHub Desktop.
string as a key in object
This file contains hidden or 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
const type = 'coke'; | |
const drinks = { | |
coke: 'Coke', | |
pepsi: 'Pepsi', | |
lemonade: 'Lemonade', | |
default: 'Default item', | |
num: 1, | |
}; | |
console.log(drinks[type]); | |
console.log(drinks.num); | |
console.log(drinks.coke); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment