Home  >  Article  >  Web Front-end  >  What is the difference between using js string indexof and search?

What is the difference between using js string indexof and search?

php中世界最好的语言
php中世界最好的语言Original
2018-04-14 17:26:112105browse

This time I will bring you jsStringWhat is the difference between using indexof and search, and Notes on using js string indexof and searchWhat are they? The following is a practical case. Let’s take a look.

In the current use of js, many people are not very clear about the difference between the indexof method and the search method. The following article will give you a detailed introduction to the specific differences between them. If you are interested, let’s take a look. .

1.indexof method

The indexOf() method returns the first occurrence of a specified string value in a string.

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 search for a specified string based on a regular expression (can ignore case, and does not perform a global search), and has no optional parameters (that is, setting the starting search position).

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How to pass parameters between vue-router components

Vue.js mobile component library Instructions

The above is the detailed content of What is the difference between using 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
Previous article:How vue calls mock dataNext article:How vue calls mock data