<!DOCTYPE HTML><html ><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>数组</title><script type="text/javascript"> //创建数组 var myarr=["#","$$","***","&&"]; myarr[8]="^^^"; //显示数组长度 var arrLength=myarr.length; alert arrLength; //将数组内容输出,完成达到的效果。 for(var i=0; i<arrLength; i++){ document.write(myarr["+i+"]+"<br>") }</script></head><body></body></html>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>数组</title>
<script type="text/javascript">
//创建数组
var myarr = ["#", "$$", "***", "&&"];
myarr[8] = "^^^";
//显示数组长度
var arrLength = myarr.length;
alert arrLength;
//将数组内容输出,完成达到的效果。
for (var i = 0; i < arrLength; i++) {
document.write(myarr["+i+"] + "<br>")
}
</script>
</head>
<body></body>
</html>
<!DOCTYPE HTML><html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>数组</title> <script type="text/javascript"> //创建数组 var myarr = ["#", "$$", "***", "&&"]; myarr[8] = "^^^"; //显示数组长度 var arrLength = myarr.length; alert arrLength; //将数组内容输出,完成达到的效果。 for (var i = 0; i < arrLength; i++) { document.write(myarr["+i+"] + "<br>") } </script></head><body></body></html>
alert arrLength 出错 alert(arrLength)
myarr["+i+"]+"<br>" 出错,for循环已经i++了, myarr[i]