美文网首页vue、javascript
js 数组中的include方法

js 数组中的include方法

作者: 源大侠 | 来源:发表于2021-02-19 11:45 被阅读0次

    平时我们写多表达式的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