js String object methods simple summary

Please note the distinction between the object and the base string JavaScript string value (for Boolean and Numbers as well)
string literal (single or double quotes by definition), and a direct call method String (String object instance is not generated by new) of strings are the basic string. JavaScript substantially automatically convert the string to a string object, the method can only be used after a String object to a String object base string conversion. When the base string only needs to call a method or a string object when the query value (substantially no string of these methods), JavaScript substantially automatically string into a string object and call the appropriate methods or execute the query.

String.prototype.concat () method to the one or more original strings and string concatenation combined to form a new string and returns. (Strongly recommended assignment operator "+" "+ =" instead concat method, since performance problems)
String.prototype.padEnd () method will be filled with a string of the current string, returns after filling to achieve a specified length. From the end of the string begins to fill the current
filling String.prototype.padStart () method for the current string to another string, returns after filling to achieve a specified length. From the beginning of the current character begins to fill the
String.prototype.repeat () constructs and returns a new string, a string containing the specified number of changes are connected together string copy
String.prototype.replace () method returns a replacement of new string values replace some or all of the pattern matching. Mode may be a string or a regular expression, alternatively the value can be a string or a callback
String.prototype.toLowerCase () method of the string of the method calls into lowercase, and returns
String.prototype.toUpperCase () method calls this method to convert a string to uppercase and returns
String.prototype.trim () at both ends of the string method will delete blank characters
String.prototype.trimRight () / trimEnd () method from a string remove empty string right
String.prototype.trimLeft () / trimStart () method to remove an empty string from the left end of a string


Substring Returns:
String.prototype.slice () method extracts a part of a string and returns a new string
String.prototype.subString () method returns a string beginning to the end of a sub-index index between set

Returns an array:
String.prototype.split () method uses the specified delimiter string String object into an array of strings, the string has been divided into sub-strings, to determine the position of each split

Comparison string search method:
String.prototype.startsWith () method is used to determine whether the current string begins with another given string, and return true or false based on the result
String.prototype.endsWith () method is used to determine whether a current string in another given string "end", and based on the result returns true or to false
String.prototype.includes () method for determining whether a character string contained in another string, returns some cases true or false
String.prototype.indexOf () method returns the index of the specified value of calling String object of the first occurrence of the search is started at fromIndex, not found -1 is returned
String.prototype.lastIndexOf () method returns the specified value this method is called the string of the last occurrence of, if not found -1 is returned. Find a forward from the back of the string, starting at fromIndex
String.prototype.search () method performs a search for a match between a regular expression and a String object, if the match is successful regular expression returns the first match in a string to the index, otherwise -1

Guess you like

Origin blog.csdn.net/pangwoniu/article/details/90478049