JS多重判断 / ES6 includes
Array.includes () 判断数组是否包含某个元素
直接返回true或者false表示是否包含元素,对NaN一样能有有效
const arr = ['1', '2', 'a', 'b' , NaN ]
console.log('%s', arr1.includes('c'))
console.log('%s', arr1.includes('1'))
console.log('%s', arr1.includes(NaN))
结果
false
true
true
includes()函数的第二个参数表示判断的起始位置。
const arr1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', NaN]
console.log('%s', arr1.includes('d', 1))
console.log('%s', arr1.includes('d', 3))
console.log('%s', arr1.includes('d', 4))
结果:
true
true
false
第二个参数也可以是负数,表示从右数过来第几个,但是不改变判断搜索的方向,搜索方向还是从左到右。
console.log('%s', arr1.includes('k', -1))
console.log('%s', arr1.includes('k', -2))
console.log('%s', arr1.includes('i', -3))
结果:
false
true
false
JS多重判断 / ES6 includes的更多相关文章
- JS流程控制语句 多重判断满足你各种需求 要在多组语句中选择一组来执行,使用if..else嵌套语句。
多重判断(if..else嵌套语句) 要在多组语句中选择一组来执行,使用if..else嵌套语句. 语法: if(条件1) { 条件1成立时执行的代码} else if(条件2) { 条件2成立时执行 ...
- JS数据类型判断的几种方法
JS数据类型判断 JavaScript 中常见数据类型有Number.String.Boolean.Object.Array.Json.Function.Date.RegExp.Error.undef ...
- js中判断对象具体类型
大家可能知道js中判断对象类型可以用typeof来判断.看下面的情况 <script> alert(typeof 1);//number alert(typeof "2" ...
- JS代码判断IE6,IE7,IE8,IE9!
JS代码判断IE6,IE7,IE8,IE9!2011年12月15日 星期四 14:01做网页有时候会用到JS检测IE的版本,下面是检测Microsoft Internet Explorer版本的三种代 ...
- JS中判断鼠标按键的问题
JS中判断鼠标按键的问题.IE左键是 window.event.button = 1右键是 window.event.button = 2中键是 window.event.button = 4没有按键 ...
- Vue.js多重组件嵌套
Vue.js多重组件嵌套 Vue.js中提供了非常棒的组件化思想,组件提高了代码的复用性.今天我们来实现一个形如 <app> <app-header></app-head ...
- Atitit js版本es5 es6新特性
Atitit js版本es5 es6新特性 Es5( es5 其实就是adobe action script的标准化)1 es6新特性1 Es5( es5 其实就是adobe action scrip ...
- ----------jqery和js如何判断checkbox是否选中 --------两个单选按钮如何选一个,且用jquery获取被选的值
jqery和js如何判断checkbox是否选中 jquery: <div id="divId" class="divTable"> <div ...
- js/jQuery判断浏览器名称、内核版本、浏览器壳
1.js方法 /* 判断浏览器名称和版本 目前只能判断:ie/firefox/chrome/opera/safari 2012年5月16日23:47:08 浏览器内核UA:UA; 浏览器内核名称:NV ...
随机推荐
- Promise在await报错后,如何继续往下跑...
一.resolve 当a>0时,正常情况依次输出A.B.C console.log("A"); let result = await this.test(); console ...
- 关于IE和360安全浏览器如何添加百度搜索为默认的搜索引擎
以IE和360浏览器为例,细心的人可能会发现.IE浏览器默认使用的必应搜索引擎(cn.bing.com) 而360安全浏览器默认使用的好搜搜索引擎.(haosou.com),对于两种浏览器,我们都可以 ...
- thinkCMF----调用幻灯片
还是在Common.php上写: /* * slide 获取幻灯片 * 具体使用: <?php $slide = slide();?> <foreach name="sli ...
- Spark特征(提取,转换,选择)extracting, transforming and selecting features
VectorAssembler字段转换成特征向量 import org.apache.spark.ml.feature.VectorAssembler val colArray = Array(&qu ...
- 通过JS模拟select表单,达到美化效果[demo][转]
转自: http://www.cnblogs.com/dreamback/p/SelectorJS.html 通过JS模拟select表单,达到美化效果 Demo ------------------ ...
- 7.20 python线程3
2018-7-20 18:46:49 去俺弟家玩去 后天回来 1.复习 # !/usr/bin/env python # !--*--coding:utf-8 --*-- # !@Time :2018 ...
- poj2492 A Bug's Life【并查集】
Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assume ...
- poj2406 Power Strings 【KMP】
Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc&quo ...
- OpenCV学习笔记之课后习题练习2-5
5.对练习4中的代码进行修改,参考例2-3,给程序加入滚动条,使得用户可以动态调节缩放比例,缩放比例的取值为2-8之间.可以跳过写入磁盘操作,但是必须将变换结果显示在窗口中. 参考博文:blog.cs ...
- iOS多线程编程之GCD介绍(转载)
一.简单介绍 1.什么是GCD? 全称是Grand Central Dispatch,可译为“牛逼的中枢调度器” 纯C语言,提供了非常多强大的函数 2.GCD的优势 GCD是苹果公司为多核的并行运算提 ...