I am a newbie at js and trying to create a 2D array but when I run the code I get in the console
Array(10) [ <10 empty slots> ] even though I filled the array with values.
This is my js and HTML:
function Make2Darray(cols, rows) {
let arr = new Array(cols);
for (let i = 0; i < arr.lenght; i++) {
arr[i] = new Array(rows);
for (let j = 0; j < rows; j++) {
arr[i][j] = floor(random(2));
}
}
return arr;
}
let grid;
grid = Make2Darray(10, 10);
console.log(grid);
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Game of Life</title>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.min.js"></script>
<script type="text/javascript" src="gol.js"></script>
</head>
<body>
</body>
</html>
lengthnotlenghtarr.length.