[javascript] How can I add a key/value pair to a JavaScript object?

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.

_x000D_
_x000D_
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_
_x000D_
_x000D_

CASE - 2 : Using dot notation

_x000D_
_x000D_
var rectangle = { width: 4, height: 6 };
rectangle.length = 7;
console.log(rectangle);
_x000D_
_x000D_
_x000D_

CASE - 3 : Using [square] notation

_x000D_
_x000D_
var rectangle = { width: 4, height: 6 };
    rectangle["length"] = 7;
    console.log(rectangle);
_x000D_
_x000D_
_x000D_