The following describes how a String consists of zero or multiple characters. Characters can contain letters, numbers, punctuation marks, and spaces. Js has nine data types: undefined, null, boolean, string, and number), object, reference, and completion ). The last three data types only serve as the intermediate result of JS running, so they cannot be used in the Code. The following describes the String:
A string consists of zero or multiple characters. Characters can contain letters, numbers, punctuation marks, and spaces. Word
The string must be enclosed in single or double quotation marks:
--------------------------------
For example, var a = 'shingbi little C ';
Var a = "shingpen small c ";
--------------------------------
Single quotation marks and double quotation marks can be used at will. However, if a string contains double quotation marks, the entire character should be
Put strings in single quotes;
A string has the length attribute and returns the number of characters in the string.
---------------------------------
Example:
Var a = "hell world ";
Alert (a. length );
Result: 11;
---------------------------------
The Slice, substring, and substr methods take a substring from the string, where
Slice and substring both accept two parameters, which are the start position and end position of the sub-string respectively.
Sub-string, excluding the character at the ending position. If the 2nd parameters are not set
Position to the end of the string.
Example:
Use Slice and substring to retrieve the string:
The Code is as follows: