Methods of String ObjectMethod 1: indexOf() (recommended)var str = "123"; console.log(str.indexOf("3") != -1 ); // true The indexOf() method returns the position of the first occurrence of a specified string value within a 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 search for a specified substring in a string, or to search for 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 a specified value within a string, or finds matches for one or more regular expressions. RegExp Object MethodsMethod 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 a 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 matches of a regular expression within a string. Returns an array containing the matching results. If no match is found, the return value is null. SummarizeThis article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: Use IISMonitor to monitor web pages and automatically restart IIS
>>: Rounding operation of datetime field in MySQL
Table of contents Optimization of if judgment 1. ...
The inline-block property value becomes very usef...
Currently I have made a project, the interface is ...
Table of contents 1. Shopping cart example 2. Cod...
Table of contents Overview Checking setTimeout() ...
Method 1: Use cmd command First, open our DOS win...
question: My blog encoding is utf-8. Sometimes whe...
Public name of the page: #wrapper - - The outer e...
Table of contents Install vim plugin manager Add ...
You need to add "gt_" in front of the f...
This article example shares the specific code of ...
margin:auto; + position: absolute; up, down, left...
Introduction: The configuration of Docker running...
Open the decompressed directory of tomcat and you...
Preface This article records how I use docker-com...