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.