简体   繁体   中英

Javascript TypeError: can't convert undefined to object

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?

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 = [];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM