set object key value code example
Example 1: javascript set object key by variable
/* FOR ES6 and Babel */
{
[yourKeyVariable]: someValueArray,
}
//for older versions
var key = "happyCount";
var obj = {};
obj[key] = someValueArray;
myArray.push(obj);
Example 2: javascript set object key as variable
let variableKey = "exampleKey"
let variableValue = "exampleValue"
//Add brackets around variableKey
let data = {
[variableKey] : variableValue
}
console.log(data)
//Return {"exampleKey": "exampleValue"}