I'd like to create JavaScript object on the fly using javascript object initializer notation, but take keys from config, so instead of
var obj = {
'key' : 'some value'
};
I'd like to have:
var config = {
myKeyName: 'key'
};
var obj = {
config.myKeyName : 'some value' // this will not work, just to illustrate
};
The question is how to place value of config.myKeyName
in this situation.
Is this possible?
Edit: I'm aware of using indexing ([]
), but that's not an option in case of deeply nested objects.