Categories
JavaScript Answers

How to add an object to an array with JavaScript?

Spread the love

To add an object to an array with JavaScript, we call the push method.

For instance, we write

const a = [];
const b = {};
a.push(b);

to call a.push with b to append b as the last element of a.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.