use value of variable as key javascript code example
Example 1: variable key name js
//You need to make the object first, then use [] to set it.
var key = "happyCount";
var obj = {};
obj[key] = someValueArray;
myArray.push(obj);
Example 2: use value of variable as key javascript
var final = [{
id: 23477234
}];
//add new object to the array using variables as keys AND values
var newArrray = {};
var key = "name";
var value = "John";
newArrray[key] = value;
final.push(newArrray);
/*
final now equals
[{
id: 23477234,
name: "John"
}]
*/