javascript variable object key code example
Example 1: javascript loop through object example
var person={
first_name:"johnny",
last_name: "johnson",
phone:"703-3424-1111"
};
for (var property in person) {
console.log(property,":",person[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: javascript variable as object key
var key = "happyCount";
var obj = {};
obj[key] = someValueArray;
myArray.push(obj);