JavaScript Tutorial/Array/Array Loop — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 11:25, 26 мая 2010
Содержание
Array Iteration
<source lang="javascript">
<HTML>
<HEAD> <TITLE> Iteration </TITLE> </HEAD> <BODY>
<SCRIPT>
var myArray = new Array(4);
myArray[0] = "A";
myArray[1] = "B";
myArray[2] = "C";
myArray[3] = "D";
myArray[6] = "E";
delete myArray[1]
for (var i = 0; i < myArray.length; i++){
if (myArray[i])
document.write("myArray[" + i + "] = " + myArray[i] + "
");
}
</SCRIPT>
</BODY>
</HTML></source>
Output all array element with document.write
<source lang="javascript">
<html> <head> <title>Writing an Array</title> </head> <body>
<script language="javascript" type="text/javascript"> </script>
</body> </html></source>
Use document.write to output the array content
<source lang="javascript">
<html> <head> <title>A Simple Page</title> <script language="JavaScript">
</script> </head> <body> </body> </html></source>
Use for each loop to change the array element value
<source lang="javascript">
<html> <head> <title>A Simple Page</title> <script language="JavaScript">
</script> </head> <body> </body> </html></source>
Use for loop to initialize an array
<source lang="javascript">
<html> <head> <title>A Simple Page</title> <script language="JavaScript">
</script> </head> <body> </body> </html></source>