js set key to object code example

Example 1: js change key value in object

var object = { boo:true, baa:5 };
console.log(object);
function change() {
  object.boo = false;
  object.baa++;
};
change();
console.log(object);
//Hope this helps!

Example 2: javascript set object key as variable

let variableKey = "exampleKey"
let variableValue = "exampleValue"
//Add brackets around variableKey
let data = {
	[variableKey] : variableValue
}

console.log(data)
//Return {"exampleKey": "exampleValue"}