JavaScript String includes() Method: Check String Contains Substring
The 'includes()' method in JavaScript is used to determine whether a string contains another specified string. It returns 'true' if the string contains the specified string and 'false' otherwise.
Here is an example:
const str = 'Hello, world!';
console.log(str.includes('world')); // Output: true
console.log(str.includes('foo')); // Output: false
In the above example, the 'includes()' method is used to check whether the string 'str' contains the substrings 'world' and 'foo'. The first 'console.log()' statement returns 'true' because the string contains 'world', while the second 'console.log()' statement returns 'false' because the string does not contain 'foo'.
原文地址: https://www.cveoy.top/t/topic/pjYy 著作权归作者所有。请勿转载和采集!