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

js 数组 包含

作者:龙之灬殇   发布日期:2025-05-01   浏览:79

// 检查数组是否包含某个元素可以使用 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() 方法用于判断数组是否包含某个指定的值,根据情况返回 truefalse
  • 在示例代码中,我们定义了一个数组 array,然后分别检查数组中是否包含数字 36,并输出相应的结果。

上一篇:js 数组方法

下一篇:js 爬虫

大家都在看

js 数组对象排序

js 数组删掉第一个值

js fill

js 数组复制

js 复制数组

js 数组拷贝

js 对象转数组

js 深拷贝数组

js 获取今天年月日

js jsonp

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

Laravel 中文站