Use array.push()
to add an item to the end of the array.
var sample = new Array();
sample.push(new Object());
To do this n
times use a for
loop.
var n = 100;
var sample = new Array();
for (var i = 0; i < n; i++)
sample.push(new Object());
Note that you can also substitute new Array()
with []
and new Object()
with {}
so it becomes:
var n = 100;
var sample = [];
for (var i = 0; i < n; i++)
sample.push({});