Created
August 27, 2014 14:19
-
-
Save egulhan/9200db4308a969f08ab2 to your computer and use it in GitHub Desktop.
How to create javascript object with dynamic key
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
| var | |
| k1='key1', | |
| k2='key2', | |
| obj={}; | |
| obj[k1]='dynamic key val 1'; | |
| obj[k2]='dynamic key val 2'; | |
| // writes "dynamic key val 1" | |
| write(obj.key1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment