Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the methods of the JavaScrip String object

Shulou Source: shulou.com Published: 2022-06-02 07:00:38 10月13日 Update

What are the methods of JavaScrip String object? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Method 1 of String object: indexOf () (recommended) var str = "123"; console.log (str.indexOf (" 3 ")! =-1); / / true

The indexOf () method returns the position where a specified string value first appears in the string. If the string value to be retrieved does not appear, the method returns-1.

Method 2: search () var str = "123"; console.log (str.search (" 3 ")! =-1); / / true

The search () method is used to retrieve a substring specified in a string or to retrieve a substring that matches a regular expression. If no matching substring is found,-1 is returned.

Method 3: match () var str = "123"; var reg = RegExp (/ 3 /); if (str.match (reg)) {/ / include}

The match () method retrieves the specified value within a string or finds a match of one or more regular expressions.

RegExp object method 4: test () var str = "123"; var reg = RegExp (/ 3 /); console.log (reg.test (str)); / / true

The test () method is used to retrieve the value specified in the string. Returns true or false.

Method 5: exec () var str = "123"; var reg = RegExp (/ 3 /); if (reg.exec (str)) {/ / include}

The exec () method is used to retrieve the match of a regular expression in a string. Returns an array containing the matching results. If no match is found, the return value is null.

This is the answer to the question about the method of JavaScrip String object. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Tags: Method character string retrieval object regular expression question middle finger more help solution easy location content available in multiple guys buddies Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MySQL Docker Redmi NVidia