Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

js array 包含

作者:一脸帅气   发布日期:2026-05-02   浏览:53

// 检查数组是否包含某个元素可以使用 Array.prototype.includes() 方法

const array = [1, 2, 3, 4, 5];

// 检查数组中是否包含数字 3
if (array.includes(3)) {
    console.log('数组包含数字 3');
} else {
    console.log('数组不包含数字 3');
}

// 检查数组中是否包含数字 6
if (array.includes(6)) {
    console.log('数组包含数字 6');
} else {
    console.log('数组不包含数字 6');
}

解释说明:

  • Array.prototype.includes() 是一个内置方法,用于检查数组是否包含某个指定的值。
  • 如果数组中包含该值,则返回 true;否则返回 false
  • 在示例代码中,我们分别检查了数组 [1, 2, 3, 4, 5] 是否包含数字 36,并根据结果输出相应的信息。

上一篇:js array fill

下一篇:js array add

大家都在看

js 数组打乱顺序

js 两个数组取交集

js 数组对象排序

js 对象数组排序

js 数组删掉第一个值

js fill

js fill方法

js 数组连接

js json数组

js 数组复制

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站