Luke
0
Q:

js variable for key obj

//You need to make the object first, then use [] to set it.

var key = "happyCount";
var obj = {};
obj[key] = someValueArray;
myArray.push(obj);
7
//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";
3
{
    [yourKeyVariable]: someValueArray,
}  
1

New to Communities?

Join the community