I am creating a 2D array using the following code:
let arr = new Array(3);
for (let i = 0; i < 5; i++){
arr[i] = new Array(5);
}
And then I try to populate it using this code:
for(let i = 0; i < arr.length; i++){
for (let j = 0; j < arr[i].length; j++){
arr[i][j] = 0;
}
}
This code works, but the time complexity is O(n^2)
. Is there any better way to do this?