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>