Set of methods for JavaScript standard types

Source: Internet
Author: User

1 Array.concat (item ...)

The Concat method produces a new array that appends one or more item to the array

var a = [' A ', ' B ', ' C ']var b = [' X ', ' y ', ' z ']var c = a.concat (b, true);//b is [' A ', ' B ', ' C ', ' X ', ' y ', ' z ', True]

  

2 Array.join (separator)

The Join method constructs an array into a string and separates them with separator

var a = [' A ', ' B ', ' C ']var c = a.join (');//C is ' abc '

  

3 Array.pop () and Array.push (item ...)

The pop and push methods allow array arrays to work like stacks

4 Array.reverse ()

The reverse method reverses the order of elements in the array and returns the array itself

5 Array.slice (Start,end)

The slice method makes a shallow copy of a paragraph in an array, first copying Array[start], which is copied to Array[end], does not change the original array, and end is optional, the default is the length of the array

var a = [' A ', ' B ', ' C ']var b = A.slice (0, 1);//[' a ']var c = c.slice (1); [' B ', ' C ']var d = d.slice; [' B ']

6 Array.Sort ()

Sort is sorting an array, but it does not correctly sort the ordered array, and we usually do some processing ourselves.

var n = [4, 8];n.sort, (A, B) {return-A-b    ;}); /n is [4, 8, 15, 16, 24, 42]

7 Array.splice (Start, DeleteCount, item ...)

The splice method is to remove one or more elements from an array, replace them with a new item, return an array containing the removed elements, DeleteCount is optional, and by default the length of the array is reduced by 1, which alters the structure of the original array

var a = [' A ', ' B ', ' C ']var r = A.splice (1, 1, ' H ', ' G ');//a is [' a ', ' h ', ' G ', ' C ']//r is [' B ']

8 function.apply (Thisarg, Argarray)

The Apply method invokes function, passes an object that is bound to this and an optional array as a parameter, and the Apply method is used in the invocation pattern

9 Number.toexponential (Franctiondigits)

The Toexponential method converts this number to a string in exponential form, and optionally the parameter controller has a value of 0-20 digits after the decimal point.

Ten number.tofixed

The Tofixed method converts this number to a string in the form of a decimal number, and the optional parameter, fractiondigits, controls the number of digits after the decimal point, whose value must be at 0-20 and the default value is 0.

Number.toprecision (Precision)

The Toprecision method converts this number to a string in decimal form, and the optional parameter controls its accuracy

Object.hasownproperty (name)

If this object contains a property named name, then the hasOwnProperty method returns True.

String.charat (POS)

The Charat method returns the character at the POS position in string, and returns an empty string if the POS small fish is 0 or greater than or equal to the length of the string string.length

var name = ' Curly '; var initial = Name.charat (0);//initial for ' C '

  

String.charcodeat (POS)

charCodeAt is the same as the Charat method, except that it returns not a string, but the character code point of the character at the POS position in the string, expressed as an integer

String.Replace (Searchvalue, Replacevalue)

The Replace method finds and replaces a string and returns a new string that, if Searchvalue is a regular expression and has a G-ID, replaces all matches, and if it does not have a G-ID, it replaces only the first match

String.Split (separator, limit)

The Split method splits the string into fragments to create an array of strings, and the optional parameter limit limits the number of fragments to be split, and the separator parameter can be a string or a regular expression

If separator is a null character, it returns an array of single characters

var digit = ' 0123456789 '; var a = Digit.split (', 5); A is [' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ']var ip = ' 192.168.1.2 '; var b = ip.split ('. '); b is [' 192 ', ' 168 ', ' 1 ', ' 2 ']

  

Set of methods for JavaScript standard types

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.