My goal is to dynamically create a JavaScript object using object initializer notation, but with keys taken from a config object. Instead of the traditional method:
var obj = {
'key' : 'some value'
};
I envision something like this:
var config = {
myKeyName: 'key'
};
var obj = {
config.myKeyName : 'some value' // this is just an illustration
};
The challenge lies in how to incorporate the value of config.myKeyName
in this particular scenario.
Is there a way to achieve this?
Update: I am familiar with using indexing ([]
), but that may not be feasible for deeply nested objects.