Construct a javascript multi-dimensional array constructor by shawl. Qiu

Source: Internet
Author: User
Construct a javascript multi-dimensional array constructor by shawl. Qiu

Note:
First, the JS array is one-dimensional...
If you want to create a multi-dimensional array, you have to create an array in the array element...
Most of the time, this is understandable.

If you know that an n-dimensional array is required, use this troublesome method...
That's too unfriendly...

Therefore, the monks constructed such a multi-dimensional array constructor... hope to facilitate operations on multi-dimensional arrays.

Shawl. Qiu
2007-09-19
Http://blog.csdn.net/btbtd

Demo:
Http://files.myopera.com/btbtd/web/Multi-Array_Constructor.htm

Content: <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> shawl. Qiu template </title>
<Style type = "text/CSS">
/* <! [CDATA [*/

/*]> */
</Style>
<SCRIPT type = "text/JavaScript">
/* <! [CDATA [*/
If (navigator. appname = "Microsoft Internet Explorer ")
{
// Maximize the window
Self. moveTo (-5,-5)
Self. resizeTo (screen. availwidth + 8, screen. availheight + 8)
// The width defined by this script is actually a little larger than that defined by the original window.
}
/*] */
</SCRIPT>
</Head>
<Body>
<SCRIPT type = "text/JavaScript">
/* <! [CDATA [*/
VaR AR = farray (2, 3, 4)
Document. write (AR. length + "" + Ar [0]. length + "" + Ar [0] [0]. length + "" + typeof (AR [0] [0] [0]), "<br/> ");
 
VaR AR = farray (10, 10)
Document. Write (AR. Length + "" + Ar [0]. Length + "" + typeof (AR [0] [0]), "<br/> ");
// Alert (AR. length)
 
Function farray ()
{// Shawl. Qiu code, return array; FUNC: fgetarg
VaR Len = arguments. length;
If (LEN = 0) return [];

VaR Arg = fgetarg. Apply (this, arguments );
// Alert (Arg. Slice (1 ))

VaR AR = new array (arguments [0]);

For (VAR I = 0, j = arguments [0]; I <j; I ++)
{
If (LEN> 1)
Ar [I] = farray. Apply (null, Arg. Slice (1 ))
} // End

If (typeof (AR [0]) = "undefined ")
{
VaR COUNT = ar. length;
For (VAR I = 0; I <count; I ++)
Ar [I] = "";
}

Return Ar;
} // End function farray ()
 
Function fgetarg ()
{// Shawl. Qiu code, return Array
VaR AR = [];
VaR Len = arguments. length;
For (VAR I = 0; I <Len; I ++)
{
Ar [I] = arguments [I];
}
Return Ar;
} // End function fgetarg ()
/*] */
</SCRIPT>
</Body>
</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.