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
This article example shares the specific code of ...
There has been a lot of discussion about H1 recent...
mysql efficient query MySQL sacrifices group by t...
This article example shares the specific code of ...
In fact, there are many corresponding writing met...
You must have saved other people’s web pages and l...
Install grafana. The official website provides an...
Table of contents 1. Basic grammar 2. Filter by c...
Preface The reason for writing this article is mai...
1. Add alternative text to your logo This has two...
Using Dockerfile allows users to create custom im...
Today I will introduce two HTML tags that I don’t...
1- Styling dropdown select boxes - Modify the dro...
This article shares the specific code of JavaScri...