我正在尝试用随机数填充 javascript 中的二维数组。尽管数组中的每一列都是随机的,但每一行都是相同的,这不是我想要的(见下图)。我希望行和列都是随机的。
http://eeldesigns.com/image.jpg
cols = 5;
rows = 10;
front = new Array(cols).fill(new Array(rows));
// Loop through Initial array to randomly place cells
for(var x = 0; x < cols; x++){
for(var y = 0; y < rows; y++){
front[x][y] = Math.floor(Math.random()*5);
}
}
console.table(front) ;