How to use search() in javascript

青灯夜游
Release: 2021-12-29 18:13:33
Original
3946 people have browsed it

In JavaScript, the search() method is used to retrieve a specified substring in a string, or to retrieve a substring that matches a regular expression, and returns the position of the first occurrence of the substring. The syntax "string .search(searchvalue)"; if no matching substring is found, "-1" is returned.

How to use search() in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

javascript search() method--search string

The search() method is used to retrieve the specified substring in the string, Or retrieve a substring that matches a regular expression.

Syntax:

string.search(searchvalue)
Copy after login

Parameter description:

  • ##searchvalue Required. The string or regular expression to search for.

Return value:

  • Returns the String object that matches the specified search string or regular expression. starting position.

  • If no matching substring is found, -1 is returned.

Example:

Perform a case-sensitive search

    

单击显示查找的位置

Copy after login

How to use search() in javascript## Perform a case-ignoring search

    

单击显示查找的位置

Copy after login

How to use search() in javascript[Related recommendations:

javascript learning tutorial

]

The above is the detailed content of How to use search() in javascript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!