Javascript learning-array

Source: Internet
Author: User
<% -- 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 ();"   />

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.