這樣為什么不能啊
<!DOCTYPE? HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>數(shù)組</title>
<script type="text/javascript">
?var arr=['*','##',"***","&&","****","##"];//創(chuàng)建數(shù)組
?arr[7]="**";
?var va={arr[0],arr[7],arr[2],arr[4]};
?for(int i=0;i<va.length;i++){
???? document.write(va[i]+'<br/>');
?}
?//顯示數(shù)組長度
/* document.write(arr.length+'<br/>');
document.write(arr[0]+'<br/>');
document.write(arr[7]+'<br/>');
document.write(arr[2]+'<br/>');
document.write(arr[4]+'<br/>');*/
/*for(int i=0;i<arr.length;i++){
?? if(arr !=undefined){
?????? document.write(arr[i]+'<br/>');
?? }? ?
?}*/
?//將數(shù)組內(nèi)容輸出,完成達到的效果。
</script>
</head>
<body>
</body>
</html>?for(int i=0;i<va.length;i++){
???? document.write(va[i]+'<br/>');
?}
?//顯示數(shù)組長度
?document.write(arr.length+'<br/>');
/*document.write(arr[0]+'<br/>');
document.write(arr[7]+'<br/>');
document.write(arr[2]+'<br/>');
document.write(arr[4]+'<br/>');*/
/*for(int i=0;i<arr.length;i++){
?? if(arr !=undefined){
?????? document.write(arr[i]+'<br/>');
?? }? ?
?}*/
?//將數(shù)組內(nèi)容輸出,完成達到的效果。
</script>
</head>
<body>
</body>
</html>
2017-03-04
你的arr[7]前面arr[6]根本沒有任何的值。數(shù)組的下標(biāo)是從0開始的。你剛開始時創(chuàng)建了一個長度為6的數(shù)組。下標(biāo)最大是5,你把arr[6]給越過去,直接給arr[7]去賦值是不對的。數(shù)組是連續(xù)的。