|| 或 语法 语法糖
一般情况 ||
function test(fruit) { if (fruit == 'apple' || fruit == 'strawberry') { console.log('red'); } }
但是有很多的或 || 那难道要写 很多 用 includes 函数 即可解决
function test(fruit) { // 条件提取到数组中 const redFruits = ['apple', 'strawberry', 'cherry', 'cranberries']; if (redFruits.includes(fruit)) { console.log('red'); } }


浙公网安备 33010602011771号