javascript date objects array objects two dimensional array instructions


1. Date object

Format:     date object name =new Date([date parameter]) Date parameter: 1. Ellipsis (most commonly used)                                                             2.

                                                :today=new Date(” October 1,2008 12:00:00 ”);

                                        3. Numerical format: month, day, AD,[hour, minute, second]

                                            today=new Date(2008,10,1);

<html>
<head>
<script type="text/javascript">
var date=new Date();
var day=date.getDay();
if(day==0){
    day=" day ";
}
document.write(" Now time : "+(date.getYear()+1900)+" years "+(date.getMonth()+1)+" month "+date.getDate()+" day "+"  week "+day+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds());
</script>
</head>
</html>

2. Array objects

Create array object:                     format 1: array object name =new Array([number of elements])

                    format 3: array object name =[element 1[, element 2…]]

The array length is variable, and the array element type can be different

                fruit=new Array(3); / / fruit = new Array ();

                      fruit[0]= “apple”;        

                                fruit [1] = “pear”;

                        fruit [2] = “orange”;              

                     

                      fruit=[” apple ”, “pear”, “orange”]; // most used

<html>
<head>
<script type="text/javascript">
//var fruits= new Array(" apple "," pears "," The oranges ");// More often
//var fruits= [" apple "," pears "," The oranges "];// It is recommended to define and initialize the array as this , That's the way it's used the most
var fruits=new Array(4);// With less
fruits[0]=" apple ";
fruits[1]=" pears ";
fruits[2]=" The oranges ";
fruits[3]=" banana ";
for(var i=0;i<fruits.length;i++){
    document.writeln("fruit["+i+"]="+fruits[i]+"<br>");
}
</script>
</head>
</html>

3. 2 dimensional array

<html>
<head>
<script type="text/javascript">
var fruits=new Array(3);
fruits[0]=new Array(" apple ",2);
fruits[1]=new Array(" pears ",3);
fruits[2]=new Array(" peach ",4);
for(var i=0;i<fruits.length;i++){
    for(var j=0;j<fruits[i].length;j++){
        document.writeln("fruits["+i+"]["+j+"]="+fruits[i][j]+"</br>");
    }
    document.writeln("</br>");
}
</script>
</head>
</html>