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

js includes用法

作者:饮尽孤单   发布日期:2025-04-24   浏览:116

// 使用 includes 方法检查数组中是否包含某个元素
const fruits = ['apple', 'banana', 'orange'];

if (fruits.includes('banana')) {
  console.log('数组中包含 banana');
} else {
  console.log('数组中不包含 banana');
}

// 使用 includes 方法检查字符串中是否包含某个子字符串
const message = 'Hello, world!';

if (message.includes('world')) {
  console.log('字符串中包含 world');
} else {
  console.log('字符串中不包含 world');
}

解释说明:

  • includes 方法可以用于数组和字符串,用于检查其中是否包含指定的元素或子字符串。
  • 对于数组,includes 返回一个布尔值,表示数组中是否包含指定的元素。
  • 对于字符串,includes 同样返回一个布尔值,表示字符串中是否包含指定的子字符串。

上一篇:js assert

下一篇:js xhr

大家都在看

js 数组对象排序

js 数组删掉第一个值

js fill

js 数组复制

js 复制数组

js 数组拷贝

js 对象转数组

js 深拷贝数组

js 获取今天年月日

js jsonp

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

Laravel 中文站