variable for object key code example
Example 1: javascript for key in object
const object = { a: 1, b: 2, c: 3 };
for (const property in object) {
console.log(`${property}: ${object[property]}`);
}
Example 2: variable key name js
var key = "happyCount";
var obj = {};
obj[key] = someValueArray;
myArray.push(obj);
Example 3: javascript create object key from variable
{
[yourKeyVariable]: "yourValue",
}
var yourObject = {};
yourObject[yourKeyVariable] = "yourValue";
Example 4: js variable for key obj
{
[yourKeyVariable]: someValueArray,
}