Home>Article>Web Front-end> What are the string methods in javascript
String methods include: charAt(), indexOf(), match(), repeat(), replace(), search(), slice(), split(), substr(), trim(), valueOf(), toString(), etc.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
JavaScript String Object
JavaScript strings are used to store and process text.
Usually, JavaScript strings are primitive values and can be created using characters:var firstName = "John"
But we can also use the new keyword to define a string As an object:var firstName = new String("John")
Example:
var x = "John"; var y = new String("John"); typeof x // 返回 String typeof y // 返回 Object
String object is used to process text (string).
Methods of String object
Method | Description |
---|---|
charAt() | Returns the character at the specified position. |
charCodeAt() | Returns the Unicode encoding of the character at the specified position. |
concat() | Concatenates two or more strings and returns a new string. |
fromCharCode() | Convert Unicode encoding to characters. |
indexOf() | Returns the position where a specified string value first appears in the string. |
includes() | Find whether the specified substring is included in the string. |
lastIndexOf() | Search the string from back to front, and calculate the last occurrence of the returned string starting from the starting position (0). |
match() | Find a match for one or more regular expressions. |
repeat() | Copy the string a specified number of times, concatenate them together and return. |
replace() | Find the matching substring in the string and replace the substring that matches the regular expression. |
search() | Find values that match a regular expression. |
slice() | Extracts a fragment of a string and returns the extracted part in a new string. |
split() | Split the string into a string array. |
startsWith() | Check whether the string starts with the specified substring. |
substr() | Extracts the specified number of characters from the string from the starting index number. |
substring() | Extract the characters between two specified index numbers in the string. |
toLowerCase() | Convert the string to lowercase. |
toUpperCase() | Convert the string to uppercase. |
trim() | Remove the whitespace on both sides of the string |
toLocaleLowerCase() | According to the local The host's locale converts the string to lowercase. |
toLocaleUpperCase() | Convert the string to uppercase according to the local host's locale. |
valueOf() | Returns the original value of a string object. |
toString() | Returns a string. |
[Recommended learning:javascript advanced tutorial]
The above is the detailed content of What are the string methods in javascript. For more information, please follow other related articles on the PHP Chinese website!