There are 9 data types in js, namely: undefined, null, boolean, string, number, object, reference, and list (completion). The latter three are only used as data types for the intermediate results of JS execution, so they cannot be used in code. Let’s talk about String first:
A string consists of zero or more characters. Characters can include letters, numbers, punctuation marks, and spaces. The word
string must be enclosed in single or double quotes:
------------------------------ ----
Example: var a='Magic pen small c';
var a="Magic pen small c";
--------------- ------------------
Single quotes and double quotes can be used casually. However, if the string contains double quotes, the entire string should be
Put it in single quotes;
The string has the length attribute, which can return the number of characters in the string
------------------------ ---------
Example:
var a="hell world";
alert(a.length);
Result: 11;
---- -----------------------------
Slice, substring, and substr methods are to take a substring from a string, where
slice and substring both accept two parameters, which are the starting position and the ending position of the substring, and return the substring between the two
, excluding the ending position. character. If the second parameter is not set, it will be from the starting
position to the end of the string.
Example:
Use Slice and substring methods to extract strings: