Study Notes on JavaScript advanced programming (5): Local JavaScript objects

Source: Internet
Author: User


(1) array:

Method 1:
VaR avalue = new array (20 );
Method 2:
VaR avalue = new array ();
Avalue [0] = "";
Avalue [1] = "B ";
...
Method 3:
VaR avalue = new array ("A", "B ",...)
Method 4:
VaR avalue = ["A", "B",...] (the array class is not explicitly declared)

The avalue. Join (parameter) method connects the array items. The connector is a parameter.

Avalue = new array ("A", "B", "C ")
Avalue. Join ("-") // output: "a-B-c"

A reverse method is: String. Split (parameter. Convert string type to array
VaR scolor = "green ";
VaR acolor = scolor. Split (""); // obtain the array ["g", "r", "E", "E", "n"];

The Concat () and slice () Methods of the array class are the same as those of the string class.

The push (), pop (), unshift (), shift (), and method of the array class provide their similar stack (later, first, first, and foremost) and similar Queue (first-in-first-out lilo.

Array_name.reverse () Reverse the array order
Array_name.sort () sorts arrays.
Array_name.splice () inserts data items into the middle of the array (very useful and interesting .)

(2) Date:

Commonly used:
VaR _ date = new date ();
VaR _ year = _ date. getfullyear (); current year
VaR _ month = _ date. getmonth (); current month
VaR _ day = _ date. getdate (); current day

Alert (_ date. totimestring (). Split ("") [0]); current hour, minute, and second

(3) Global built-in objects

Special functions such as isnan () and parseint () are their functions.

The biggest difference between encodeuri (), encodeuricomponent (), decodeuri (), decodeuricomponet (), and escape () in the BOM method is that escape () non-ASCII character set symbols are not encoded. Therefore, encodeuri () is recommended for encoding.

(4) math built-in object

Min ()
Max ()
ABS () absolute value,
Ceil () rounded up
Floor () rounding down
Round () Rounding
Alert (math. Ceil (25.5); // output 26
Alert (math. Floor (25.5); // output 25
Alert (math. Round (25.5); // output 26
Random () returns a random number between 0 and 1.
For example, select a random number from 1 to 10:
VaR inum = math. Floor (math. Random () * 10 + 1)

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.