javascript get object key with variable code example
Example 1: variable key name js
var key = "happyCount";
var obj = {};
obj[key] = someValueArray;
myArray.push(obj);
Example 2: js get object keys
myObject = {
"key": "value"
}
Object.keys(myObject);
Example 3: javascript create object key from variable
{
[yourKeyVariable]: "yourValue",
}
var yourObject = {};
yourObject[yourKeyVariable] = "yourValue";
Example 4: get keys of object js
var buttons = {
foo: 'bar',
fiz: 'buz'
};
for ( var property in buttons ) {
console.log( property );
}