How to push an object into an array in JavaScript?

To push an object into an array in JavaScript, do this: array.push(object).

Here's how you do it:

const array = [];
const object = {
  myField1: 24,
  myField2: 'Hello World!'
};

array.push(object);

console.log(array); // [ { "myField1": 24, "myField2": "Hello World!" } ]