当前位置:网站首页>indexof和includes的区别
indexof和includes的区别
2022-07-01 18:41:00 【屿-·】
数组中的indexof方法
判断字符串是否包含子字符串(包含的话就返回字符串所在位置,不包含返回-1)
语法:indexof(searchElement,fromIndex)
fromIndex(可选。从该索引处开始查找searchElmentui)
let str = 'orange';
str.indexOf('o'); //0
str.indexOf('n'); //3
str.indexOf('c'); //-1
数组中的includes方法
判断一个数组是否包含一个指定的值(包含返回true,不包含返回false)
语法:includes(searchElement,fromIndex)
fromIndex(可选。从该索引处开始查找searchElmentui)
var arr = [10,20,30,40,50];
arr.includes(10); //true
arr.includes(10,1); //false
indexof和includes的区别
返回值不同:
includes(): 返回布尔类型
indexof(): 返回的是一个整数的类型值,表示当前的值在数组中第一次出现的索引
NaN和undefined的处理:
indexoOf() : 不能匹配到数组中的NaN,也识别不了undefined(直接忽略)
includes() : 能匹配到数组中的NaN,也能识别稀疏数组的undefined
边栏推荐
- 一次SQL优化,数据库查询速度提升 60 倍
- Lake Shore continuous flow cryostat transmission line
- Lumiprobe biomolecular quantification - qudye Protein Quantification Kit
- Appgallery connect scenario development practice - image storage and sharing
- PMP是被取消了吗??
- linux下清理系统缓存并释放内存
- 实例讲解将Graph Explorer搬上JupyterLab
- The best landing practice of cave state in an Internet ⽹⾦ financial technology enterprise
- VBA simple macro programming of Excel
- C端梦难做,科大讯飞靠什么撑起10亿用户目标?
猜你喜欢
毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
Leetcode-21 combines two ordered linked lists
制造业SRM管理系统供应商全方位闭环管理,实现采购寻源与流程高效协同
CDGA|从事通信行业,那你应该考个数据管理证书
AI training speed breaks Moore's law; Song shuran's team won the RSS 2022 Best Paper Award
Evaluation of 6 red, yellow and black list cameras: who is the safest? Who has good picture quality? From now on, let you no longer step on thunder
Lumiprobe bifunctional crosslinker sulfo cyanine 5 bis NHS ester
Example explanation: move graph explorer to jupyterlab
Lake Shore—OptiMag 超导磁体系统 — OM 系列
docker 部署mysql8.0
随机推荐
[quick application] win7 system cannot run and debug projects using Huawei ide
VBA simple macro programming of Excel
Supervarimag superconducting magnet system SVM series
Prices of Apple products rose across the board in Japan, with iphone13 up 19%
Navicat premium 15 permanent cracking and 2021 latest idea cracking (valid for personal testing)
宏观视角看抖音全生态
Summary of the core steps in the life cycle of beans
Graduation summary
Usage and underlying implementation principle of PriorityQueue
2020,最新手机号码手机验证正则表达式,持续更新
市值蒸发740亿,这位大佬转身杀入预制菜
Solution: you can ping others, but others can't ping me
斯坦福、Salesforce|MaskViT:蒙面视觉预训练用于视频预测
Leetcode-128 longest continuous sequence
Clean up system cache and free memory under Linux
How to realize the applet in its own app to realize continuous live broadcast
洞态在某互联⽹⾦融科技企业的最佳落地实践
How to operate technology related we media well?
Love business in Little Red Book
Lumiprobe 自由基分析丨H2DCFDA说明书