JavaScript 字符串包含特定字符判断:includes() 方法
使用 JavaScript 中的 includes() 方法可以判断一个字符串中是否包含某些特定的字符。
例如,下面的代码将检查一个字符串是否包含字母'a':
let str = 'hello world';
if (str.includes('a')) {
console.log('The string contains the letter 'a'');
} else {
console.log('The string does not contain the letter 'a'');
}
如果字符串包含字母'a',则会输出'The string contains the letter 'a'',否则会输出'The string does not contain the letter 'a''。
原文地址: https://www.cveoy.top/t/topic/mrGW 著作权归作者所有。请勿转载和采集!