// 示例代码:使用 Array.includes 方法检查数组中是否包含某个元素
const fruits = ['apple', 'banana', 'orange'];
// 检查数组中是否包含 'banana'
if (fruits.includes('banana')) {
console.log('数组中包含 banana');
} else {
console.log('数组中不包含 banana');
}
// 检查数组中是否包含 'grape'
if (fruits.includes('grape')) {
console.log('数组中包含 grape');
} else {
console.log('数组中不包含 grape');
}
Array.includes()
是 JavaScript 中用于检查数组是否包含某个指定的值的方法。true
,否则返回 false
。fruits
,并使用 includes()
方法来检查数组中是否包含特定的水果(如 'banana'
和 'grape'
)。下一篇:js bind
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站