字符串方法

SOBER小于 1 分钟

字符串方法

includes() 方法

介绍: 查找字符串,如果在string 中找到子字符串includes() 方法返回true。否则,它返回 false

使用

/** 数组中使用 */
let arr = ['小明', '小杨'];
arr.includes("小明");  // 返回 true
arr.includes("明");  // 返回 false

/** 字符串中使用 */
let arr = ['小明', '小杨'];
arr.includes("小明");  // 返回 true
arr.includes("明");  // 返回 false