In Javascript, creating and adding values to object with static key can be done as below.

But sometime you may need to add object key dynamically.

If you add variable name to Object key, It will take variable name as key not variable value.

To have dynamic value as key, use [] to add value to object as below.

I hope this helps someone who is looking to add dynamic key in Javascript Object.



Software engineer who passionate about learning technology. I strongly believe that Technologies are not just to learn, Technologies are to make our life easier