var initGrid = function() {
//creating a grid while initialising it
var grid = [];
// declaring each grid element as a Object having three properties
var gridElement = {
x: Number,
y: Number,
val: Number
};
for (var i = 0; i < 10; i++) {
for (var j = 0; j < 10; j++) {
gridElement.x = i;
gridElement.y = j;
gridElement.val = 0;
grid.push(gridElement);
};
};
return grid;
};
console.log(initGrid());
when i run this code on console, all Objects of grid Array are having same values for x and y which are 9 and 9....
But i want to create objects having different values acc to loop variables