How to add a property to an object in JavaScript?

To add a key to an object JavaScript do this: object.newProperty = 123.

Here's how you do it:

const object = { someProperty: 'Hello World!' };

// {someProperty: 'Hello World!'}
console.log(object);

object.anotherProperty = 123;

// {someProperty: 'Hello World!', anotherProperty: 123}
console.log(object);