JavaScript basic knowledge of the methods of summary _javascript skills

Source: Internet
Author: User
Tags joins shallow copy

Methods of arrays:

Array.concat an array to connect to another array, returning a synthetic array. var arrc=arra.concat (ARRB, ' asd ', ' sad ', true,1.5);
Array.join joins the array with the specified symbol as a string, and returns the string. A lot faster than using a +. var stra=arra.join (",");//default to Comma
Array.pop moves the last element of the divisor group and returns the element. var a=arra.pop ();
Array.push attaches one or more parameters to the tail of the array and returns a new length value. Arra.push ("ASD");
Array.shift moves the first element of the divisor group and returns the element. It's much slower than pop, cause I think it's just a pseudo array, remove the first one to push all the elements forward. var a=arra.shift ();
Array.unshift that one or more parameters are attached to the head of the array. Arra.unshift ("ASD");
Array.reverse reverses the order of the elements in the array. var arrb=arra.reverse ();
Array.slice the array to make a shallow copy. It then assigns an array between the two subscripts, returning a new array. var arrb=arra.slice (0,3);//Take the 0,1,2 element out and the back 3 may not fill
Array.Sort sorts the contents of an array. Arra.sort ()//By default, the elements are converted to strings and compared. Of course, you can also pass a comparison function as an argument.
Arra.sort (function (a,b) {
return a-b;
});
Array.splice removes one or more elements from the array and replaces them with new elements. var arrb=arra.splice (0,3, ' ASD ', ' ads ');//Remove 3 elements starting with subscript 0 and replace with the following two elements

Method of the function:

Function.apply calls a function, passing an object that is bound to this, and an optional array as an array of arguments.

Number of methods:

Number.toexponential converts this number to a string of exponential form. Math.PI.toExponential (2);//3.14e+0
Number.tofixed converts this number to a decimal-number-form string. Math.PI.toFixed (2);//3.14, two decimal digits reserved
Number.toprecision converts this number to a decimal-number-form string. Math.PI.toPrecision (2);//3.1, two valid digits retained
Number.tostring converts this number to a string. Math.PI.toString (2);//Here 2 represents the system, not the precision.

Method of the object:

Object.hasownproperty Determines whether an object contains a property named with the specified string

Method of regular expression:

Regexp.exec
If the match succeeds, an array is returned. Subscript 0 Returns the matching original string, followed by the 1~ of the grouped 1~ captured text.
If you have a G identity (global identity), the lookup begins at a location that does not start at the beginning of the string, but Regexp.lastindex. If the match succeeds, then the Regexp.lastindex is set to the position of the first character of the string that matches the success, otherwise reset to 0.
Regexp.test returns True if a successful match, otherwise false

Method of String:

String.charat returns the character at the specified position in the string
String.charcodeat returns the ASCII code value of the character at the specified position in the string
String.Concat joins other strings together, returning a new synthetic string. Actually with + more convenient, and more intuitive.
String.IndexOf finds the specified other string in this string and, if found, returns the position of the first found string, otherwise returns-1. ASDASD ". IndexOf (" SD ", 2);//value 4, 2 indicates starting from 3rd character lookup
String.LastIndexOf This is similar to the above, except to start looking at the tail of the string
String.localecompare compares two strings. Stra.localecompare (STRB)//The result is return positive, negative, 0, you know.
String.Replace an operation that finds and replaces a string, and returns a new string (the method with the following name red) that can be applied to a regular expression.

General methods:

' ASDASD '. Replace (' as ', ' d ');//The result is Ddasd,replace will only replace the first occurrence position.

Regular Expression method:

Add G logo match multiple times, no match once

var regexp=/ee (asd\d{0,3})/g;//plus g identification matches multiple times without matching once
var p= ' eeasd1323 '. Replace (REGEXP, ' $1end ');//result is Eeasd1323end
The ' $1end ' position can also put a function, each match to run this function, and then replace with the return value of the function, here is not to raise chestnuts
The explanation for the ' $1end ' is this:
$$: the symbol for $
$&amp: Represents $& the entire match to the text
$number: Text that is captured by a group, such as the above, which captures the text captured by group 1
$ ': Match the previous text
$ ': Text after match
String.match to match a string with a regular expression. It depends on the G tag to determine how to match.
If there is no G ID, the match result is the same as the regexp.exec effect
If it does, it will generate an array that contains all the matches (except for the captured groupings that don't know what the meaning is, which is clearly matched all)
String.search is similar to indexof, and only receives a regular expression match. This method ignores the G identity.
String.Split creates a string array by dividing the string. This method ignores the G identity.
The general play
var digits= ' 0123456789 ';
var arr=digits.split (', 5);//5 indicates that the resulting array is at most five elements, superfluous remove
The result is [' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ']
How to play regular expressions
var text= ' Troy, 123, good ';
var d=text.split (/\s*,\s*/);//Previously said \s represents Unicode various null characters, then the matching delimiter is a comma containing null characters, so that the empty characters are automatically removed, so powerful
But there are exceptions. The text from the packet capture is included in the split character, so I personally suggest that you don't capture it in groups.
String.slice copy a part of the string to construct a new string
String.substring is the same as slice effect, just cannot use negative subscript. There is no reason to use substring rather than slice (the author says). Actually, I know what I mean by literal meaning.
String.tolowercase returns a new string that is all lowercase.
String.tolocalelowercase Ditto, Turkish-only, so you can't see it.
String.touppercase returns a new string that is all capitalized.
String.tolocaleuppercase Ditto, Turkish-only, so you can't see it.
String.fromCharCode: Oh, string is uppercase. So it's not called after the string, it's called with string. Returns a string based on a string of numeric encodings. (I don't believe you're basically using it)

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.