JSP (array)

Source: Internet
Author: User

1. array list
Var arr = ["zx", "123", "4.7"];
Each array has the length attribute.

Var arr = [1, 5];
The empty element is undefeated.

Var arr = ["x +" + 1, 12.3];
The array element can be an expression.

Var arr = [[1, 2], "hello", "3.8"];
Array elements can also be arrays.
[Html]
<Html>
<Script language = "javascript">
Var arr = [1, ["zxx" + 1, "li", 3.5], ["2", "@", "1"];
For (var I = 0; I <arr. length; I ++)
{
If (arr [I]. length)
{
For (var j = 0; j <arr [I]. length; j ++)
{
Alert (arr [I] [j]);
}
} Else
{
Alert (arr [I]);
}
}
 
 
</Script>
</Html>


2. Implement Arrays Using objects
[Html]
<Html>
<Script language = "javascript">
Function MyArray ()
{
This. length = arguments. length;
For (var I; I <this. length; I ++)
{
This [I] = arguments [I];
}
}
 
Var str = "";
Var arr = new MyArray (4, 3.5, "abo ");
For (var I = 0; I <arr. length; I ++)
{
Str + = arr [I] + "\ n ";
}
Alert (str );
 
 
Function MyArray2 (size)
{
This. length = size;
For (var I = 0; I <size; I ++)
{
This [I] = "";
}
}
Var arr2 = new MyArray2 (2 );
Arr [0] = 3;
Arr [1] = "ba ";
Arr [2] = 4;
 
Var x, str = "";
For (x in arr)
{
Str + = x + ":" + arr [x] + "\ n ";
}
 
Alert (str );
</Script>
</Html>

[Html]
<Html>
<Script language = "javascript">
Function MyArray ()
{
This. length = arguments. length;
For (var I; I <this. length; I ++)
{
This [I] = arguments [I];
}
}
 
Var str = "";
Var arr = new MyArray (4, 3.5, "abo ");
For (var I = 0; I <arr. length; I ++)
{
Str + = arr [I] + "\ n ";
}
Alert (str );
 
 
Function MyArray2 (size)
{
This. length = size;
For (var I = 0; I <size; I ++)
{
This [I] = "";
}
}
Var arr2 = new MyArray2 (2 );
Arr [0] = 3;
Arr [1] = "ba ";
Arr [2] = 4;
 
Var x, str = "";
For (x in arr)
{
Str + = x + ":" + arr [x] + "\ n ";
}
 
Alert (str );
</Script>
</Html>

3. Array object
* Array ()
[Html]
<Html>
<Script language = "javascript">
 
Var arr = new Array ();
Arr [0] = '1 ';
Arr [1] = 2;
 
Alert (arr. length );
</Script>
</Html>


* Array (4): determine the length

* Array (3.5, "abc", 3)
[Html]
<Html>
<Script language = "javascript">
 
Var arr = new Array ();
Arr [0] = '1 ';
Arr [1] = 2;
Arr [3] = 3;
Arr [4] = 0;
Arr. sort ();
Var str = "";
For (var x in arr)
{
Str + = x + ":" + arr [x] + "\ n ";
}
 
Alert (str );
 
Alert (arr. length );
</Script>
</Html>

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.