Javascript date object, array object, two-dimensional array instructions, javascript two-dimensional array

Source: Internet
Author: User

Javascript date object, array object, two-dimensional array instructions, javascript two-dimensional array

I. date object

Format: Date object name = new Date ([Date parameter])
Date parameter: 1. omitted (most commonly used)
2. English-parameter format: Month/day, AD year [hour: minute/second]

For example, today = new Date ("October 12:00:00 ");

3. Value format: year, month, day, [hour, minute, second]

For example, today = new Date (, 1 );

Copy codeThe Code 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>

Ii. array objects

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

Format 2: Array object name = new Array ([[element 1] [, element 2,…])

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

Variable array length, array element types can be different

For example, fruit = new Array (3); // fruit = new Array ();

Fruit [0] = "apple ";

Fruit [1] = "Pear ";

Fruit [2] = "orange ";


Fruit = new Array ("apple", "Pear", "orange ");

Fruit = ["apple", "Pear", "orange"]; // The most used

Copy codeThe Code is as follows:
<Html>
<Head>
<Script type = "text/javascript">
// Var fruits = new Array ("apple", "Pear", "orange"); // more
// Var fruits = ["apple", "", "orange"]; // we recommend that you define and initialize arrays in this way. This method is the most used.

Var fruits = new Array (4); // use less
Fruits [0] = "apple ";
Fruits [1] = "Pear ";
Fruits [2] = "orange ";
Fruits [3] = "banana ";
For (var I = 0; I <fruits. length; I ++ ){
Document. writeln ("fruit [" + I + "] =" + fruits [I] + "<br> ");
}
</Script>
</Head>
</Html>

3. Two-dimensional array

Copy codeThe Code is as follows:
<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>

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.