how to set variable as key in javascript object code example
Example 1: variable key name js
var key = "happyCount";
var obj = {};
obj[key] = someValueArray;
myArray.push(obj);
Example 2: javascript create object key from variable
{
[yourKeyVariable]: "yourValue",
}
var yourObject = {};
yourObject[yourKeyVariable] = "yourValue";
Example 3: javascript set object key as variable
let variableKey = "exampleKey"
let variableValue = "exampleValue"
let data = {
[variableKey] : variableValue
}
console.log(data)