The contains() method in JavaScript is used to determine whether a string contains another substring. Returns true if included; otherwise, returns false.
contains() usage in JavaScript
Answer the question:
contains () method is used to determine whether a string contains another substring. Returns true if included; otherwise, returns false.
Expand answer:
Grammar:
<code>string.contains(substring)</code>
Among them,
string
is the string to search for. substring
is the substring to be found. Parameters:
Parameters | Description |
---|---|
substring | The substring to be found |
Return value:
Return value | Description |
---|---|
true | If the string contains subcharacters String |
false | If the string does not contain a substring |
Example:
<code>const str = "Hello, World!"; console.log(str.includes("Hello")); // 输出:true console.log(str.includes("Universe")); // 输出:false</code>
Note:
The above is the detailed content of How to use contains in js. For more information, please follow other related articles on the PHP Chinese website!