Home > Article > Web Front-end > The difference between indexof and search methods based on js string (graphic tutorial)
Below I will share with you an introduction to the differences between the JS string indexof and search methods. It has a good reference value and I hope it will be helpful to 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 the specified substring in the string, or search with a regular expression matching substring.
Note: The search method can search for the specified string based on a regular expression (can ignore case, and does not perform a global search), At the same time, there are no optional parameters (that is, setting the starting search position).
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Detailed explanation of JS cross-domain POST implementation steps
Summary of JS operation DOM tree traversal method
JS gets the least common multiple and the greatest common divisor
The above is the detailed content of The difference between indexof and search methods based on js string (graphic tutorial). For more information, please follow other related articles on the PHP Chinese website!