Today I was looking into creating a javascript object with a dynamic key name. I came to these docs and thought there was hope, but alas, new object literal features are only available in ES6. I was fooled by using the Chrome console to think it was an ES5 feature. I always forget that Chrome supports ES6.

In ES5 you have to do this.

var key = 'dynamicKey';
var o = {};
o[key] = 'value';

But in ES6, when creating an object literal, you can do this:

var key = 'dynamicKey';
var o = { [key]: 'value' };

A little funky, but the world will be a better place when ES5 doesn’t need to be supported.