wizi Posted June 9, 2010 Share Posted June 9, 2010 function setDefaultScores (s1, s2) //s1: vertical, s2: horizontal, (i=s1; j=s2) { var arrayDS = new Array(); for (var i = 0; i < s1.length; i++) { for (var j =0; i < s2.length; j++) { if (s1.charAt(i) == s2.charAt(j)) { arrayDS[i][j] =1; } else { arrayDS[i][j] = 0; } } } } When I call this function. I got an error "Typeerror: arrayDS is undefined." at arrayDS[j] =1;Can someone show me how to solve this? I don't see anything wrong with this function. Even when I change arrayDS[0] = 1; it still gives me the same error. Thank you very much. Link to comment Share on other sites More sharing options...
boen_robot Posted June 9, 2010 Share Posted June 9, 2010 You have just one dimensional array. In other words, each array member must also be an array itself, and you must define it at every level.Try it like that: function setDefaultScores (s1, s2) //s1: vertical, s2: horizontal, (i=s1; j=s2){ var arrayDS = new Array(); for (var i = 0; i < s1.length; i++) { arrayDS[i] = new Array(); for (var j =0; i < s2.length; j++) { if (s1.charAt(i) == s2.charAt(j)) { arrayDS[i][j] =1; } else { arrayDS[i][j] = 0; } } }} Link to comment Share on other sites More sharing options...
wizi Posted June 9, 2010 Author Share Posted June 9, 2010 Oh, i got it. Thank you so much. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.