We can add a key/value pair to a JavaScript object in many ways...
CASE - 1 : Expanding an object
Using this we can add multiple key: value
to the object at the same time.
const rectangle = { width: 4, height: 6 };
const cube = {...rectangle, length: 7};
const cube2 = {...rectangle, length: 7, stroke: 2};
console.log("Cube2: ", cube2);
console.log("Cube: ", cube);
console.log("Rectangle: ", rectangle);
_x000D_
CASE - 2 : Using dot
notation
var rectangle = { width: 4, height: 6 };
rectangle.length = 7;
console.log(rectangle);
_x000D_
CASE - 3 : Using [square]
notation
var rectangle = { width: 4, height: 6 };
rectangle["length"] = 7;
console.log(rectangle);
_x000D_