Current location - Quotes Website - Signature design - How does the front end judge how many specified characters are in a string?
How does the front end judge how many specified characters are in a string?
1. Use indexOf (), indexOf () to return the position where the specified string value first appears in the string. The string value to be retrieved does not appear, and the method returns-1.

2. Use search (), which is used to retrieve the substring specified in the string or the substring matching the regular expression. No matching substring found, returning-1.

3. Use test (), and the test () method is used to retrieve the value specified in the string. Returns true or false.

4. Use the exec () and exec () methods to retrieve the matches of regular expressions in the string. Returns an array containing matching results. No match found, and the return value is empty.