有很多判断的时候你可能会这么写:
if(
type == 1 ||
type == 2 ||
type == 3 ||
type == 4 ||
){
//...
}
使用ES6的includes后:
const condition = [1,2,3,4];
if( condition.includes(type) ){
//...
}
有很多判断的时候你可能会这么写:
if(
type == 1 ||
type == 2 ||
type == 3 ||
type == 4 ||
){
//...
}
使用ES6的includes后:
const condition = [1,2,3,4];
if( condition.includes(type) ){
//...
}
本文标题:关于ES6的includes
本文链接:https://www.haomeiwen.com/subject/aweisrtx.html
网友评论