平时我们写多表达式的if判断
if (x === 'abc' || x === 'def' || x === 'ghi' || x ==='jkl') {
// 其他
}
可以换成这样的
if (['abc', 'def', 'ghi', 'jkl'].includes(x)) {
// 其他
}
平时我们写多表达式的if判断
if (x === 'abc' || x === 'def' || x === 'ghi' || x ==='jkl') {
// 其他
}
可以换成这样的
if (['abc', 'def', 'ghi', 'jkl'].includes(x)) {
// 其他
}
本文标题:js 数组中的include方法
本文链接:https://www.haomeiwen.com/subject/crqaxltx.html
网友评论