I am practicing Javascript and have the following code which returns an Uncaught TypeError: Cannot set property '0' of undefined error on the sets[i][j] = initial_sets [i][j]; line. The idea seems to be correct, but I can't figure out why I am getting the error.
var sets = [[],[]]; //Declared this 2D array based on solution in https://stackoverflow.com/questions/16512182/how-to-create-empty-2d-array-in-javascript
var initial_sets=[[a,b],[c,d],[e,f]]; //2D array
var i,j;
//2D array sets is being filled by 2D array initial_sets
for (i=0; i<initial_sets.length; i++) {
for (j=0; j<initial_sets[i].length; j++) {
sets[i][j] = initial_sets[i][j];
}
}
I tried the solution posted in Uncaught TypeError: Cannot set property '0' of undefined " by creating a 1D array and then assigning another dimension to it, but I still get the same error.
initial_setsbut only 2 insetssoset[2]isundefinedinitial_setsis a 2D array though