Home  >  Article  >  Web Front-end  >  Detailed explanation of the difference between js string indexof and search

Detailed explanation of the difference between js string indexof and search

小云云
小云云Original
2018-01-05 10:27:472400browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn