String object
String object is used to process text (String ).
Syntax for creating a String object:
new String(s);String(s);
Parameters
ParametersSIs the value to be stored in the String object or converted to the original String.
Return Value
When String () and the new operator are used as constructors, it returns a newly created String object that stores strings.SOrS.
When the new operator is not used to call String (),SConvert to the original string and return the converted value.
String object attributes
FF: Firefox, IE: Internet Explorer
Attribute
Description
FF
IE
Constructor
Reference to the function that creates the object
1
4
Length
String Length
1
3
Prototype
Allows you to add attributes and methods to an object
1
4
String object Method
FF: Firefox, IE: Internet Explorer
Method
Description
FF
IE
Anchor ()
Create an HTML anchor.
1
3
Big ()
Use a large font to display strings.
1
3
Blink ()
Displays a flashing string.
1
Bold ()
Use bold to display strings.
1
3
CharAt ()
Returns the characters at the specified position.
1
3
CharCodeAt ()
Returns the Unicode encoding of characters at the specified position.
1
4
Concat ()
The connection string.
1
4
Fixed ()
Displays strings in typewriter text.
1
3
Fontcolor ()
Use the specified color to display the string.
1
3
Fontsize ()
Use the specified size to display the string.
1
3
FromCharCode ()
Creates a string from the character encoding.
1
4
IndexOf ()
Returns a string.
1
3
Italics ()
Use italics to display strings.
1
3
LastIndexOf ()
Search for strings from the back and forward.
1
3
Link ()
Display the string as a link.
1
3
LocaleCompare ()
Compares two strings in a specific local order.
1
4
Match ()
Find the matching of one or more regular expressions.
1
4
Replace ()
Replace the substring that matches the regular expression.
1
4
Search ()
Returns the value that matches the regular expression.
1
4
Slice ()
Extract the string segment and return the extracted part in the new string.
1
4
Small ()
Use a small font size to display strings.
1
3
Split ()
Splits a string into a string array.
1
4
Strike ()
Use strikethrough to display strings.
1
3
Sub ()
Returns the string as a subscript.
1
3
Substr ()
Extracts a specified number of characters from the start index number.
1
4
Substring ()
Extract the characters between two specified index numbers in the string.
1
3
Sup ()
Displays the string as a superscript.
1
3
ToLocaleLowerCase ()
Converts a string to lowercase.
-
-
ToLocaleUpperCase ()
Converts a string to uppercase.
-
-
ToLowerCase ()
Converts a string to lowercase.
1
3
ToUpperCase ()
Converts a string to uppercase.
1
3
ToSource ()
The source code of the object.
1
-
ToString ()
Returns a string.
-
-
ValueOf ()
Returns the original value of a string object.
1
4
String object description
A string is a basic data type of JavaScript.
The length attribute of the String object declares the number of characters in the String.
The String class defines a large number of String operations, such as extracting characters or substrings from a String, or retrieving characters or substrings.
It should be noted that JavaScript strings are immutable, and the methods defined by the String class cannot change the content of strings. A method like String. toUpperCase () returns a brand new String instead of modifying the original String.
In the earlier JavaScript Implementation of Netscape code base (such as Firefox implementation), the string behavior is like a read-only character array. For example, to extract the third character from string s, use s [2] instead of s. charAt (2 ). In addition, when a for/in loop is applied to a string, it will enumerate the array subscript of each character in the string (but note that the length attribute cannot be enumerated according to ECMAScript standards ). Because the string array behavior is not standard, avoid using it.