Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
94
rated 0 times [  95] [ 1]  / answers: 1 / hits: 34715  / 11 Years ago, mon, august 12, 2013, 12:00:00
var horizont, vertikal = new Array ()

for (var i=0; i < 9; i++)
{
horizont[i] = new Array ();
vertikal[i] = new Array ()
}


That's what the console told me:




TypeError: can't convert undefined to object




horizont[i] = new Array ();


(if I would erase it from the code he says the same with vertikal )



except from some other empty strings getiing born it's the beginning of my code...
where is the mistake?
Is it so ovious that I don't see it?


More From » object

 Answers
28

The error is because you did not define horizont as an Array. You are using a comma to separate your variable so it is undefined. It does not use the new Array() from vertikal.



If you take your code



var horizont, vertikal = new Array ()


And write it out to use multiple variable, the error would pop out.



var horizont;
var vertikal = new Array();


You need to specify both as Arrays.



var horizont = [], 
vertikal = [];

[#76387] Saturday, August 10, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ibrahimr

Total Points: 468
Total Questions: 99
Total Answers: 93

Location: Serbia
Member since Sun, Jul 11, 2021
3 Years ago
;