// 示例代码:检查一个数组是否包含某个元素
// 使用 Array.prototype.includes() 方法
const array = [1, 2, 3, 4, 5];
const contains = array.includes(3); // 返回 true,因为数组中包含 3
console.log(contains); // 输出: true
// 如果要检查字符串是否包含某个子字符串
const str = "Hello, world!";
const containsSubstring = str.includes("world"); // 返回 true,因为字符串中包含 "world"
console.log(containsSubstring); // 输出: true
// 解释说明:
// 1. `Array.prototype.includes()` 方法用于判断数组是否包含某个指定的值,根据情况返回 true 或 false。
// 2. `String.prototype.includes()` 方法用于判断字符串是否包含某个指定的子字符串,根据情况返回 true 或 false。
上一篇:js 获取dom
下一篇:js 按钮
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站