Categories
JavaScript Answers

How to push to an array with JavaScript?

Spread the love

To push to an array with JavaScript, we use the push method.

For instance, we write

const json = [{ cool: "34.33" }, { alsocool: "45454" }];
json.push({ coolness: "34.33" });

to call json.push with an object to append it as the last item of the json array.

By John Au-Yeung

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

Leave a Reply

Your email address will not be published. Required fields are marked *