Home > Article > Web Front-end > Detailed explanation of JavaScript string processing (String object)_Basic knowledge
Define String object
JavaScript String object is used to process text strings. The syntax for creating a String object is as follows:
Run the following statements to know the difference:
String object properties
属性 | 描述 |
---|---|
constructor | 对创建该对象的函数的引用 |
length | 字符串的长度 |
prototype | 向对象添加属性和方法 |
String object method
The list of common methods of String object is as follows:
String output
alert(): Message warning box output text
document.write(): Output text to the Web page
String operations
concat(): Concatenate two or more strings
replace(): String replacement or regular match replacement
slice(): intercept a string by specifying the start and end positions
split(): Split the string into a string array
substr(): intercept the string according to the starting position and length
substring(): intercept the string
String conversion
toLowerCase(): Convert the string to lowercase
toUpperCase(): Convert the string to uppercase
fromCharCode(): Convert one or more Unicode values to a string
String search
charAt(): Get the character at the specified position
charCodeAt(): Get the Unicode encoding of the character at the specified position
indexOf(): Calculate the position where a specified string first appears in the string
lastIndexOf(): Calculate the position where a specified string first appears in the string
HTML tag class
bold(): Get the character at the specified position
fontcolor(): Display the string according to the specified color
fontsize(): Display the string according to the specified size
italics(): Display the string in italics
link(): Add a hyperlink to a string
strike(): Add strikethrough to the string
sub(): Display the string as a subscript
sup(): Display the string as superscript