let yourKeyVariable = "Fire";
{
[yourKeyVariable]: someValue,
}
/* object will resolve to { Fire : someValue } */
/*
This is similar to adding k-v pair to an object using the other syntax
ie. object[yourKeyVariable] = someValue;
*/
let yourKeyVariable = "objectKeyName";
//For ES6 and Babel
{
[yourKeyVariable]: "yourValue",
}
// ES5 Alternative
// Create the object first, then use [] to set your variable as a key
var yourObject = {};
yourObject[yourKeyVariable] = "yourValue";
// RESULT:
// {
// "objectKeyName": "yourValue"
// }
var key = "happyCount";
var obj = {};
obj[key] = someValueArray;
myArray.push(obj);
var key = "happyCount";
var obj = {};
obj[key] = someValueArray;
myArray.push(obj);