I created a helper function to create 2D arrays but it always returns NaN values in Chrome.
var H = new Object();
H.N = 10;
H.M = 3;
function array2D(N,M,v){
var temp = new Array(N);
for(var i=0; i<N; i++){
temp[i] = new Array(M);
for(var j=0; j<M; j++){
temp[i][j] = v;
}
}
console.log(temp);
return temp;
}
H.A = new array2D(H.N, H.M, 1/H.M);
When I print v, the correct value is given but the array still has the NaN values for each entry. I have looked at answers to these questions so far: 1, 2 but nothing I change has worked. This is my first time working with Javascript; can someone explain my error?