当前位置:网站首页>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
边栏推荐
- R language ggplot2 visualization: visualize the line graph and add customized Y-axis label information to the line graph using the labels function
- Salesmartly has some tricks for Facebook chat!
- Usage and underlying implementation principle of PriorityQueue
- 摄像头的MIPI接口、DVP接口和CSI接口[通俗易懂]
- Cache problems after app release
- 洞态在某互联⽹⾦融科技企业的最佳落地实践
- Leetcode-128 longest continuous sequence
- Viewing the whole ecology of Tiktok from a macro perspective
- R language uses the transmute function of dplyr package to calculate the moving window mean value of the specified data column in dataframe data, and uses ggplot2 package to visualize the line graph b
- CDGA|从事通信行业,那你应该考个数据管理证书
猜你喜欢
ACM MM 2022视频理解挑战赛视频分类赛道冠军AutoX团队技术分享
水产行业智能供应链管理平台解决方案:支撑企业供应链数字化,提升企业管理效益
前4A高管搞代运营,拿下一个IPO
MySQL常用图形管理工具 | 黑马程序员
Li Kou daily question - Day 32 -589 N × Preorder traversal of tree
The best landing practice of cave state in an Internet ⽹⾦ financial technology enterprise
Create your own NFT collections and publish a Web3 application to show them (Introduction)
Lumiprobe 亚磷酰胺丨六甘醇亚磷酰胺说明书
Intensive cultivation of channels for joint development Fuxin and Weishi Jiajie held a new product training conference
Halcon image calibration enables subsequent image processing to become the same as the template image
随机推荐
太爱速M源码搭建,巅峰小店APP溢价寄卖源码分享
AI 训练速度突破摩尔定律;宋舒然团队获得RSS 2022最佳论文奖
Basic knowledge and commands of disk
Stanford, salesforce|maskvit: masked vision pre training for video prediction
How to use the low code platform of the Internet of things for personal settings?
Games202 operation 0 - environment building process & solving problems encountered
C-end dream is difficult to achieve. What does iFLYTEK rely on to support the goal of 1billion users?
Huawei game failed to initialize init with error code 907135000
Supervarimag superconducting magnet system SVM series
Clean up system cache and free memory under Linux
如何在自有APP内实现小程序实现连麦直播
2020, the regular expression for mobile phone verification of the latest mobile phone number is continuously updated
数据仓库(四)之ETL开发
The market value evaporated by 74billion yuan, and the big man turned and entered the prefabricated vegetables
[AGC] how to solve the problem that the local display of event analysis data is inconsistent with that in AGC panel?
Today, with the popularity of micro services, how does service mesh exist?
小红书上的爱情买卖
ETL development of data warehouse (IV)
bean的生命周期核心步骤总结
PMP是被取消了吗??