Method one, the definition and initialization of JS array
Defining a one-dimensional array
Method 1:
var _thearray = new Array);//define
_thearray[0]= "1";
_thearray[1]= "2";
_thearray[2]= "3";
Class
Method 2:
var _thearray = new Array ("1", "2", "3");//directly defined and initialized
Defining two-dimensional arrays
Method 1
var _thearray = new Array (); First declare one dimension
for (Var i=0;i<10;i++) { //One dimension length of
thearray[i]=new Array (); In the declaration two-dimensional
for (Var j=0;j<20;j++) { //two-D length
_thearray[i][j]=1
}
}
Method 2
var _thearray = [["0-1", "0-2"],["1-1", "1-2"],["2-1", "2-2"]];//directly defined and initialized
The above code is tested under IE8
method Two,
<script type= "Text/javascript" >
var date=new date ();
function Initarray () {
this.length=initarray.arguments.length;
for (Var i=0;i<this.length;i++) {
this[i]=initarray.arguments[i];
}
}
var d=new initarray (
' Sunday ',
' Monday ',
' Tuesday ',
' Wednesday ',
' Thursday ',
' Friday ',
' Saturday '
);
The Firfox browser displays the year by getyear () to get the current year minus 1900
document.write ((Date.getyear () >1900?date.getyear ():d ate.getyear ( ) (+1900) + "year");
document.write (Date.getmonth () +1+ "Month");
document.write (Date.getdate () + "Day");
document.write (D[date.getday ());
</script>
Because JavaScript does not support arrays, the following code is used to define the initialization array.
function Initarray () {
This.length=initarray.arguments.length;
for (Var i=0;i<this.length;i++) {
This[i]=initarray.arguments[i];
}
}