// 示例代码:使用 includes() 方法检查数组中是否包含某个元素
const fruits = ['apple', 'banana', 'orange'];
// 检查数组中是否包含 'banana'
if (fruits.includes('banana')) {
console.log('数组中包含 banana');
} else {
console.log('数组中不包含 banana');
}
// 输出: 数组中包含 banana
// includes() 方法也可以用于字符串,检查字符串中是否包含某个子字符串
const message = 'Hello, world!';
// 检查字符串中是否包含 'world'
if (message.includes('world')) {
console.log('字符串中包含 world');
} else {
console.log('字符串中不包含 world');
}
// 输出: 字符串中包含 world
includes() 方法用于检查数组或字符串中是否包含指定的元素或子字符串。includes() 返回 true 或 false,表示该元素是否存在。includes() 同样返回 true 或 false,表示该子字符串是否存在。上一篇:js includes方法
下一篇:js includes
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站