Categories
JavaScript Answers

How to create JavaScript array (JSON format) dynamically?

Spread the love

Sometimes, we want to create JavaScript array (JSON format) dynamically.

In this article, we’ll look at how to create JavaScript array (JSON format) dynamically.

How to create JavaScript array (JSON format) dynamically?

To create JavaScript array (JSON format) dynamically, we call the array push method.

For instance, we write

const students = [];
const obj = {
  firstName: name,
  lastMame: name,
  age: age,
};
students .push(obj);

to call students.push with obj to add the obj object as the last entry of the students array.

Conclusions

To create JavaScript array (JSON format) dynamically, we call the array push method.

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 *