1. Date object
Format: Date object name = new Date([Date Parameter])
Date parameters: 1. Omitted (most commonly used)
2. English-parameter format: month and day, first year [hour: minute and second]
For example: today=new Date("October 1,2008 12:00:00");
3. Numerical format: First year, month, day, [hour, minute, second]
For example: today=new Date(2008,10,1);
The code copy is as follows:
<html>
<head>
<script type="text/javascript">
var date=new Date();
var day=date.getDay();
if(day==0){
day="day";
}
document.write("Current time: "+(date.getYear()+1900)+"year"+(date.getMonth()+1)+"month"+date.getDate()+"day+" week"+day+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds());
</script>
</head>
</html>
2. Array object
Create an array object:
Format 1: Array object name = new Array([number of elements])
Format 2: Array object name = new Array([[Element1][,Element2,…]])
Format 3: Array object name = [Element 1[, Element 2,…]]
The array length is variable, and the array element types can be different
For example: fruit=new Array(3);//fruit=new Array();
fruit[0]=”Apple”;
fruit[1]=”Da Li”;
fruit[2]=”Orange”;
fruit=new Array("apple","duck pear","orange");
fruit=["Apple","Dape","Orange"];//The most used
The code copy is as follows:
<html>
<head>
<script type="text/javascript">
//var fruits= new Array("apple","dairy pear","orange");//There are more commonly used
//var fruits= ["Apple","Dape","Orange"];//It is recommended to define and initialize the array in this way, and this method is used the most
var fruits=new Array(4);// Use less
fruits[0]="Apple";
fruits[1]="Da Li";
fruits[2]="orange";
fruits[3]="banana";
for(var i=0;i<fruits.length;i++){
document.writeln("fruit["+i+"]="+fruits[i]+"<br>");
}
</script>
</head>
</html>
Three-dimensional array
The code copy is as follows:
<html>
<head>
<script type="text/javascript">
var fruits=new Array(3);
fruits[0]=new Array("Apple",2);
fruits[1]=new Array("Ya Li",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>