JS-判断数组是否包含某个数 布满荆棘的人生 2022-05-20 06:59 226阅读 0赞 #### 前言 #### 实际开发经常遇到这样的需求:判断数组是否包含某个数; 在2016年发布ECMAScript的第个七版ECMScript 2016即是es7中的新特性有一个方法includes(),可用此方法来判断。 #### 代码 #### [1, 2, 3].includes(2); // true [1, 2, 3].includes(4); // false [1, 2, 3].includes(3, 3); // false #### 总结 #### 截止2018.7月,大多数主流的浏览器已经支持这个新特性,可通过以下网站查看浏览器支持情况: > [https://caniuse.com/\#feat=array-includes][https_caniuse.com_feat_array-includes] [https_caniuse.com_feat_array-includes]: https://caniuse.com/#feat=array-includes
还没有评论,来说两句吧...