当前位置:网站首页>The difference between indexof and includes
The difference between indexof and includes
2022-07-01 19:20:00 【Lantau-·】
Array indexof Method
Determine whether a string contains substrings ( If it is included, the position of the string will be returned , Does not include return -1)
grammar :indexof(searchElement,fromIndex)
fromIndex( Optional . Start at this index to find searchElmentui)
let str = 'orange';
str.indexOf('o'); //0
str.indexOf('n'); //3
str.indexOf('c'); //-1
Array includes Method
Determine whether an array contains a specified value ( Include return true, Does not include return false)
grammar :includes(searchElement,fromIndex)
fromIndex( Optional . Start at this index to find searchElmentui)
var arr = [10,20,30,40,50];
arr.includes(10); //true
arr.includes(10,1); //false
indexof and includes The difference between
Different return values :
includes(): return Boolean type
indexof(): Back to a Integers Type value of , Indicates the index of the first occurrence of the current value in the array
NaN and undefined To deal with :
indexoOf() : You can't Match to in array NaN, I can't recognize undefined( Direct to ignore )
includes() : can Match to in array NaN, Can also recognize sparse arrays undefined
边栏推荐
- Cdga | if you are engaged in the communication industry, you should get a data management certificate
- MySQL common graphics management tools | dark horse programmers
- Golang error handling
- Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?
- kubernetes命令入门(namespaces,pods)
- The market value evaporated by 74billion yuan, and the big man turned and entered the prefabricated vegetables
- Team up to learn! 14 days of Hongmeng equipment development "learning, practicing and testing" practical camp, free of charge!
- 241. Different Ways to Add Parentheses
- docker 部署mysql8.0
- Clean up system cache and free memory under Linux
猜你喜欢
洞态在某互联⽹⾦融科技企业的最佳落地实践
Bao, que se passe - t - il si le serveur 100 + O & M a mal à la tête? Utilisez le majordome xingyun!
C-end dream is difficult to achieve. What does iFLYTEK rely on to support the goal of 1billion users?
Lake Shore continuous flow cryostat transmission line
11. Users, groups, and permissions (1)
bean的生命周期核心步骤总结
Lake Shore - crx-em-hf low temperature probe station
实例讲解将Graph Explorer搬上JupyterLab
Lake shore M91 fast hall measuring instrument
寶,運維100+服務器很頭疼怎麼辦?用行雲管家!
随机推荐
2020, the regular expression for mobile phone verification of the latest mobile phone number is continuously updated
C-end dream is difficult to achieve. What does iFLYTEK rely on to support the goal of 1billion users?
Database foundation: select basic query statement
Lumiprobe 活性染料丨吲哚菁绿说明书
毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
市值蒸发740亿,这位大佬转身杀入预制菜
【快应用】Win7系统使用华为IDE无法运行和调试项目
洞态在某互联⽹⾦融科技企业的最佳落地实践
Netease games, radical going to sea
Create your own NFT collections and publish a Web3 application to show them (Introduction)
[6.24-7.1] review of wonderful technical blog posts in the writing community
Solution: you can ping others, but others can't ping me
Lake Shore continuous flow cryostat transmission line
数据仓库(四)之ETL开发
Boost the development of digital economy and consolidate the base of digital talents - the digital talent competition was successfully held in Kunming
JS find the next adjacent element of the number in the array
M91快速霍尔测量仪—在更短的时间内进行更好的测量
Qfile read / write file operation in QT
AI training speed breaks Moore's law; Song shuran's team won the RSS 2022 Best Paper Award
CDGA|从事通信行业,那你应该考个数据管理证书