当前位置:网站首页>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
边栏推荐
- 华为游戏初始化init失败,返回错误码907135000
- R language uses the aggregate function of epidisplay package to divide numerical variables into different subsets based on factor variables, and calculate the summary statistics of each subset
- Leetcode-141 circular linked list
- Lumiprobe 自由基分析丨H2DCFDA说明书
- Technical secrets of ByteDance data platform: implementation and optimization of complex query based on Clickhouse
- Is PMP cancelled??
- Implement a Prometheus exporter
- app发版后的缓存问题
- Love business in Little Red Book
- Lumiprobe biomolecular quantification - qudye Protein Quantification Kit
猜你喜欢

CDGA|从事通信行业,那你应该考个数据管理证书

Livedata postvalue will "lose" data

Privacy sandbox is finally coming

What designs are needed in the architecture to build a general monitoring and alarm platform

Lake Shore continuous flow cryostat transmission line

Lake Shore M91快速霍尔测量仪

11、用户、组和权限(1)

中英说明书丨人可溶性晚期糖基化终末产物受体(sRAGE)Elisa试剂盒

水产行业智能供应链管理平台解决方案:支撑企业供应链数字化,提升企业管理效益

如何使用物联网低代码平台进行个人设置?
随机推荐
The R language cartools package divides the data, the scale function scales the data, the KNN function of the class package constructs the k-nearest neighbor classifier, and the table function calcula
小红书上的爱情买卖
Leetcode-160 intersecting linked list
Usage and underlying implementation principle of PriorityQueue
docker 部署mysql8.0
华为联机对战服务玩家掉线重连案例总结
js找出数字在数组中下一个相邻的元素
Love business in Little Red Book
What designs are needed in the architecture to build a general monitoring and alarm platform
Lumiprobe bifunctional crosslinker sulfo cyanine 5 bis NHS ester
R language uses follow up of epidisplay package Plot function visualizes the longitudinal follow-up map of multiple ID (case) monitoring indicators, and uses n.of The lines parameter specifies the num
Prices of Apple products rose across the board in Japan, with iphone13 up 19%
Intensive cultivation of channels for joint development Fuxin and Weishi Jiajie held a new product training conference
宏观视角看抖音全生态
华为云专家详解GaussDB(for MySQL)新特性
Create your own NFT collections and publish a Web3 application to show them (Introduction)
Lumiprobe 细胞成像研究丨PKH26细胞膜标记试剂盒
Altair HyperWorks 2022 software installation package and installation tutorial
市值蒸发740亿,这位大佬转身杀入预制菜
Altair HyperWorks 2022软件安装包和安装教程