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({});

Depending on what you mean by declaring, you can try using object literals in an array literal:

var sample = [{}, {}, {} /*, ... */];

EDIT: If your goal is an array whose undefined items are empty object literals by default, you can write a small utility function:

function getDefaultObjectAt(array, index)
{
    return array[index] = array[index] || {};
}

Then use it like this:

var sample = [];
var obj = getDefaultObjectAt(sample, 0);     // {} returned and stored at index 0.

Or even:

getDefaultObjectAt(sample, 1).prop = "val";  // { prop: "val" } stored at index 1.

Of course, direct assignment to the return value of getDefaultObjectAt() will not work, so you cannot write:

getDefaultObjectAt(sample, 2) = { prop: "val" };

You can use fill().

let arr = new Array(5).fill('lol');

let arr2 = new Array(5).fill({ test: 'a' });
// or if you want different objects
let arr3 = new Array(5).fill().map((_, i) => ({ id: i }));

Will create an array of 5 items. Then you can use forEach for example.

arr.forEach(str => console.log(str));

Note that when doing new Array(5) it's just an object with length 5 and the array is empty. When you use fill() you fill each individual spot with whatever you want.


After seeing how you responded in the comments. It seems like it would be best to use push as others have suggested. This way you don't need to know the indices, but you can still add to the array.

var arr = [];
function funcInJsFile() {
    // Do Stuff
    var obj = {x: 54, y: 10};
    arr.push(obj);
}

In this case, every time you use that function, it will push a new object into the array.