JavaScript数组常用操作和遍历方法
5.使用includes简化if判断 // bad if (a === 1 || a === 2 || a === 3 || a === 4) { // todo }
// good let arr = [1, 2, 3, 4] if (arr.includes(a)) { // todo } 复制代码 巧用数组方法,尽量避免用for循环
JavaScript数组常用操作和遍历方法
5.使用includes简化if判断 // bad if (a === 1 || a === 2 || a === 3 || a === 4) { // todo }
// good let arr = [1, 2, 3, 4] if (arr.includes(a)) { // todo } 复制代码 巧用数组方法,尽量避免用for循环