数组和字符串的includes() 一招简写if判断条件
// 数组使用
let arr = [1, 5, 7]
let a = 7
let bool = arr.includes(a)
console.log('bool: ', bool); // true a 等于 1、5、7 bool 都为true
// 用法简写 一个元素多个值 if判断
if (a === 1 || a === 5 || a === 7) {
console.log(111111111111);
}
// 简写
if (arr.includes(a)) {
console.log(111111111111);
}
// 字符串使用
const str = '苏州abc56'
const boolA = str.includes('ab')
console.log('boolA: ', boolA); // true
const boolB = str.includes('Ab')
console.log('boolB: ', boolB); // false
// 注意 includes 区分大小写
// 本期上图 lsp们
世界上只有一种真正的英雄主义,那就是在认清生活的真相后依然热爱生活。
浙公网安备 33010602011771号