关于ES6的includes

2022-04-19  本文已影响0人  泪滴在琴上

有很多判断的时候你可能会这么写:

if(
    type == 1 ||
    type == 2 ||
    type == 3 ||
    type == 4 ||
){
   //...
}

使用ES6的includes后:

const condition = [1,2,3,4];

if( condition.includes(type) ){
   //...
}
上一篇 下一篇

猜你喜欢

热点阅读