为什么第二种输出就是undefined
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>二维数组</title> <script type="text/javascript"> var myarr = new Array(); //1 for(var i=0;i<3;i++){ myarr[i] = new Array(); for(var j=0;j<6;j++){ myarr[i][j]=i*j; document.write(myarr[i][j]); } document.write("<br />"); } //2 for(var i=0;i<3;i++){ myarr[i] = new Array(); for(var j=0;j<6;j++){ document.write(myarr[i][j]); } document.write("<br />"); } </script> </head> <body> </body> </html>
结果
000000
012345
0246810
undefinedundefinedundefinedundefinedundefinedundefined
undefinedundefinedundefinedundefinedundefinedundefined
undefinedundefinedundefinedundefinedundefinedundefined