当前位置:网站首页>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
边栏推荐
- 2020, the regular expression for mobile phone verification of the latest mobile phone number is continuously updated
- 磁盘的基本知识和基本命令
- SuperOptiMag 超导磁体系统 — SOM、SOM2 系列
- How to use the low code platform of the Internet of things for personal settings?
- R language ggplot2 visualization: visualize the line graph and add customized Y-axis label information to the line graph using the labels function
- Lumiprobe lumizol RNA extraction reagent solution
- Viewing technological changes through Huawei Corps (VI): smart highway
- 1. "Create your own NFT collections and publish a Web3 application to show them." what is NFT
- OpenAI|视频预训练 (VPT):基于观看未标记的在线视频的行动学习
- Leetcode-83 delete duplicate elements in the sorting linked list
猜你喜欢

Why do independent website sellers start to do social media marketing? The original customer conversion rate can be improved so much!

毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?

Viewing technological changes through Huawei Corps (VI): smart highway

3. "Create your own NFT collections and publish a Web3 application to show them" cast NFT locally

After studying 11 kinds of real-time chat software, I found that they all have these functions

磁盘的基本知识和基本命令

linux下清理系统缓存并释放内存

Halcon image calibration enables subsequent image processing to become the same as the template image

The former 4A executives engaged in agent operation and won an IPO

Lake Shore continuous flow cryostat transmission line
随机推荐
Viewing technological changes through Huawei Corps (VI): smart highway
Taiaisu M source code construction, peak store app premium consignment source code sharing
R language ggplot2 visualization: gganimate creates a dynamic histogram animation (GIF), and displays the histogram and enter step by step along a given dimension in the animation_ Growth function and
Netease games, radical going to sea
Docker deploy mysql8.0
Games202 operation 0 - environment building process & solving problems encountered
Lumiprobe 活性染料丨吲哚菁绿说明书
有关 M91 快速霍尔测量仪的更多信息
The best landing practice of cave state in an Internet ⽹⾦ financial technology enterprise
Leetcode203 remove linked list elements
毕业总结
宏观视角看抖音全生态
Navicat Premium 15 永久破解和2021版本最新IDEA破解(亲测有效)
斯坦福、Salesforce|MaskViT:蒙面视觉预训练用于视频预测
如何使用物联网低代码平台进行个人设置?
Golang error handling
Navicat premium 15 permanent cracking and 2021 latest idea cracking (valid for personal testing)
Mipi interface, DVP interface and CSI interface of camera [easy to understand]
苹果产品在日本全面涨价,iPhone13涨19%
2020, the regular expression for mobile phone verification of the latest mobile phone number is continuously updated