JavaScript Date object, array object, two-dimensional array usage Description _ Basics

Source: Internet
Author: User
Tags array length pear

One, Date object

Format: Date Object name =new date ([date parameter])
Date parameters: 1. Omitted (most commonly used)
2. English-parameter format: month, year [time: seconds]

such as: Today=new Date ("October 1,2008 12:00:00");

3. Numerical format: Ad year, month, day, [Time, minute, second]

such as: Today=new Date (2008,10,1);

Copy Code code as follows:

<script type= "Text/javascript" >
var date=new date ();
var day=date.getday ();
if (day==0) {
Day= "Day";
}
document.write ("Now Moment:" + (Date.getyear () +1900) + "year" + (Date.getmonth () +1) + "month" +date.getdate () + "Day" + "Week" +day+ "" + Date.gethours () + ":" +date.getminutes () + ":" +date.getseconds ());
</script>

Two, Array object

To create an array object:
Format 1: Array object name =new array ([element number])

Format 2: Array object name =new array ([[element 1][, Element 2,...]])

Format 3: Array object name =[element 1[, Element 2,...]]

Array length variable, array element type can be different

such as: Fruit=new array (3);//fruit=new array ();

fruit[0]= "Apple";

fruit[1]= "Pear";

fruit[2]= "oranges";


Fruit=new Array ("Apple", "pear", "orange");

fruit=["Apple", "pear", "orange"];//use the most

Copy Code code as follows:

<script type= "Text/javascript" >
var fruits= new Array ("Apple", "pear", "orange");//More used
var fruits= ["Apple", "pear", "orange"];//recommend this to define, initialize the array, this way with the most

var fruits=new Array (4);//Less used
fruits[0]= "Apple";
fruits[1]= "Pear";
fruits[2]= "oranges";
fruits[3]= "Banana";
for (Var i=0;i<fruits.length;i++) {
Document.writeln ("fruit[" +i+ "]=" +fruits[i]+ "<br>");
}
</script>

Three or two-D array

Copy Code code as follows:

<script type= "Text/javascript" >
var fruits=new Array (3);
Fruits[0]=new Array ("Apple", 2);
Fruits[1]=new Array ("Pear", 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>

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.