From:https://www.cnblogs.com/ooo0/p/7741651.html
Method of the String object
Method One: 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 in a string. If the string value that you want to retrieve does not appear, the method returns-1.
Method Two: Search ()
var str = "123"; Console.log (Str.search ("3")! =-1); True
The search () method is used to retrieve the substring specified in a string, or to retrieve a substring that matches a regular expression. Returns 1 if no matching substring is found.
Method three: 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 for one or more regular expressions.
RegExp Object Methods
Method four: 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 five: Exec ()
var str = "123"; var reg = RegExp (/3/); if (Reg.exec (str)) { //contains }
The exec () method is used to retrieve the matching of regular expressions in a string. Returns an array that holds the results of the match. If no match is found, the return value is null.
JS to determine if a string contains a string (reproduced)