关于if中判断条件的优化

if ( type == 'a' || type =='b'  || type == 'c' || type == 'd'){

   //...

}

可使用ES6中数组实例方法includes

const condition = ['a','b','c','d'];

if ( condition.includes(type) ){
   //...
}

posted @ 2021-10-27 09:58  IsZ_Y  阅读(99)  评论(0编辑  收藏  举报