How to summarize and use JavaScript

Source: Internet
Author: User


The JavaScript method concludes:

One, Array ():

1, Shift (): Deletes the first element, returning the deleted value.

Example:

<script>

Function B (a) {

document.write (A + "<br/>");

}

var a = [8,2,3,4,5];

var shift = A.shift ();

B (Shift);

B (A.length);

}

</script>

2. Pop (): Deletes the last element, returning the deleted value.
3. Unshift (parameter): Loads the parameter to the front of the array and returns the length of the array.
4. Push (parameter): Loads the parameter to the end of the array and returns the length of the array.
5, concat (parameter): two or three arrays make up a new array.
6, Splice (0 (starting index value), 2 (number of deletions), text (the array to be inserted): Removes/inserts one or more elements from an array.
7, reverse (): Reverse the array.
8, Slice (0 (starting from [0]), 2 (2)): Returns a segment of an array

TwoDate ():

var now = new Date (); Create Date Object

1, getFullYear (); year
2, GetMonth (); month
3, GetDay ();
4, getHours ();
5, getminutes ();
6, getseconds (); seconds

ThreeMath ():

Ceil (); Take up the floor (); Take down the whole
Round (); rounding random ();

FourString ():

1, charCodeAt (index); Returns the Unicode encoding for the specified index
2, CharAt (index): Returns the character at the specified index position
3, Slice (0,2): Returns the fragment in the string (AB)
4, SubString (1,3): Returns a string of the specified length starting at the specified position (BC)
5, IndexOf ("A", 1 (starting from the 1th position)): When not found, returns a-1, when found, returns the position relative to the starting position.
6, LastIndexOf ("A", 7 (starting from the 7th position reverse)): Reverse Lookup
7, concat (): Connection string

Five, other packaging methods:

1, encodeURI (URL) decodeuri ("") (for text encoding decoding)
2, encodeURI comporent (URL) decodeuri comporent (URL) (for "/" "?" codec)
3, commonly used: eval (parameters) dynamic operation parameters.

Example: var str = "alert (123)";
eval (str);

Function: Pop-up window display 123;

How to summarize and use JavaScript

Related Article

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.