Home > Article > Web Front-end > Detailed explanation of the difference between js string indexof and search
This article mainly shares with you an introduction to the difference between the js string indexof and search methods. It has a good reference value and I hope it will be helpful to everyone. Let’s follow the editor to take a look, I hope it can help everyone.
1.indexof method
indexOf() method can return the position where a specified string value first appears in the string.
Syntax:
Note: There are optional parameters (that is, setting the starting search position).
2. Search method
The search() method is used to retrieve a specified substring in a string, or to retrieve a substring that matches a regular expression.
Note: The search method can find the specified string according to the regular expression (case can be ignored, and no global search is performed), and there are no optional parameters (that is, setting the start search location).
Related recommendations:
Detailed explanation of the use of indexof in JavaScript
How to use indexOf() and how to use it with jQuery.inArray() Difference
Detailed explanation of indexOf method in JavaScript array
The above is the detailed content of Detailed explanation of the difference between js string indexof and search. For more information, please follow other related articles on the PHP Chinese website!