Home  >  Article  >  Web Front-end  >  What is the difference between indexof and search methods in js

What is the difference between indexof and search methods in js

亚连
亚连Original
2018-06-22 17:50:361398browse

The editor below 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. Let’s follow the editor and take a look.

1.indexof method

indexOf() method can return a specified string value in The position of the first occurrence 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:

How to use vue to implement login registration and token verification

How to use Javascript to implement a custom event mechanism

How to use JavaScript to achieve the left menu effect

How to achieve the select all cancel effect in JavaScript

How to call vuex to store interface data in vue.js

The above is the detailed content of What is the difference between indexof and search methods in js. 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