<% -- Javascript Learning -- %>
< Script Type = "Text/JavaScript" Language = "JavaScript" >
Function Funarray ()
{
/*
Defines an array. Members can be single or double quotation marks.
No value is specified in the two commas (,), indicating an empty element. The empty element value is undefined.
The last element is an expression.
*/
VaR Arr = [ " Name " ,, ' Age ' , 20 + 1 ]
For ( VaR Icou = 0 ; Icou < Arr. length; icou ++ )
{
Alert (ARR [icou]);
}
}
// The array contains an array.
Function Funarrarray ()
{
/*
An array can contain arrays. Edge definition
*/
VaR Arr = [ 123 ,[ " Name " , " Scott " , ' Age ' , 20 ], [ " Xx " , " YY " , 1 ];
For ( VaR I = 0 ; I < Arr. length; I ++ )
{
// If the Length attribute does not exist, it indicates that it is an element.
If (ARR [I]. length)
{
For ( VaR J = 0 ; J < Arr [I]. length; j ++ )
{
Alert (ARR [I] [J]);
}
}
Else
{
Alert (ARR [I]);
}
}
}
// Use array to create an array
Function Funarrayfunction ()
{
VaR Arr = New Array ();
Arr [ 0 ] = " Name " ;
Arr [ 1 ] = " Scott " ;
Arr. Sort ();
For ( VaR Ival In ARR)
{
Alert (ARR [ival]);
}
}
</ Script >
<% -- Button used for testing -- %>
< Input ID = "Button1" Type = "Button" Runat = "Server" Value = "Test" Onclick = "Funarray ();" />
< Input ID = "Button2" Type = "Button" Runat = "Server" Value = "Test subarray" Onclick = "Funarrarray ();" />
< Input ID = "Button3" Type = "Button" Runat = "Server" Value = "Test subarray" Onclick = "Funarrayfunction ();" />