当前位置:网站首页>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
边栏推荐
- Games202 operation 0 - environment building process & solving problems encountered
- ES6 summary "suggestions collection" of array methods find(), findindex()
- 数商云:从规划到落地,五矿集团如何快速构建数字化发展新格局?
- linux下清理系统缓存并释放内存
- Livedata postvalue will "lose" data
- 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
- Lefse analysis
- 【快应用】Win7系统使用华为IDE无法运行和调试项目
- Leetcode-128 longest continuous sequence
- Lumiprobe 细胞成像研究丨PKH26细胞膜标记试剂盒
猜你喜欢

Openai video pre training (VPT): action learning based on watching unmarked online videos

MySQL常用图形管理工具 | 黑马程序员

Lumiprobe 亚磷酰胺丨六甘醇亚磷酰胺说明书

Getting started with kubernetes command (namespaces, pods)

宏观视角看抖音全生态

Lumiprobe 细胞成像研究丨PKH26细胞膜标记试剂盒

【直播预约】数据库OBCP认证全面升级公开课

Docker deploy mysql8.0

Viewing the whole ecology of Tiktok from a macro perspective

The former 4A executives engaged in agent operation and won an IPO
随机推荐
小红书上的爱情买卖
用GSConv+Slim Neck改进Yolov5,将性能提升到极致!
宏观视角看抖音全生态
Appgallery connect scenario development practice - image storage and sharing
ETL development of data warehouse (IV)
How to use the low code platform of the Internet of things for personal settings?
Excel之VBA简单宏编程
华为联机对战服务玩家掉线重连案例总结
R language ggplot2 visualization: gganimate package transition_ Time function to create dynamic scatter animation (GIF), shadow_ The wake function configures the gradient falloff tailing effect of the
【快应用】Win7系统使用华为IDE无法运行和调试项目
斯坦福、Salesforce|MaskViT:蒙面视觉预训练用于视频预测
Intensive cultivation of channels for joint development Fuxin and Weishi Jiajie held a new product training conference
【直播预约】数据库OBCP认证全面升级公开课
苹果产品在日本全面涨价,iPhone13涨19%
助力数字经济发展,夯实数字人才底座—数字人才大赛在昆成功举办
精益思想:来源,支柱,落地。看了这篇文章就懂了
Leetcode-21 combines two ordered linked lists
2. Create your own NFT collections and publish a Web3 application to show them start and run your local environment
[quick application] win7 system cannot run and debug projects using Huawei ide
Lake Shore 连续流动低温恒温器传输线