2020
12-05
12-05
JavaScript中条件语句的优化技巧总结
对多个条件使用Array.includesfunctiontest(fruit){if(fruit=='apple'||fruit=='strawberry'){console.log('red');}}上面的例子看起来不错。然而,如果还有更多红颜色的水果需要判断呢,比如樱桃和小红莓,我们要用更多的||来扩展这个表述吗?我们可以用Array.includes重写上面的条件!functiontest(fruit){constredFruits=['apple','strawberry','cherry','cranberries'];if(redFruits.includes(fruit...
继续阅读 >