Not sure if this can even be done, but I'll ask anyway:
Suppose if I have an array of names:
['bob', 'sue', 'dan']
And I want to dynamically create an object from those names:
bob.sue.dan = 5;
Is it possible?
Not sure if this can even be done, but I'll ask anyway: Suppose if I have an array of names:
And I want to dynamically create an object from those names:
Is it possible? |
|||
|
Here you go, will preserve existing objects:
e.g. usage:
or for your example using an array.
or extending an existing object:
Edit: updated as requested:
See working example: http://jsfiddle.net/herostwist/hu6j9/ |
|||||||||||||||||
|
|
|||
|
sure you can ...
|
|||||||||
|
Then you can do:
|
|||
|
Yes this is possible. You can define new properties on an object this way:
So you can also do it with an array of property names ;) |
|||||||||||||
|