I wanted objects like this:
[{ age: 3, area: 5 },
{ age: 4, area: 15 },
{ age: 19, area: 3 },
{ age: 16, area: 11 },
{ age: 20, area: 4 },
{ age: 6, area: 9 }]
The approach was to create new objects each time and push it inside an array.
function Numstuff(age,area) {
this.age = age,
this.area = area
}
var numObjArray = []
var createObj = new Numstuff (Math.floor(Math.random() * 20),
Math.floor(Math.random() * 20))
numObjArray.push(createObj)
But This pushes only one. How to create multiple objects and push inside an array?
NumStuffconstructor without wanting the new object added to the array, you can putnumObjArray.push(this)at the end of the constructor.