当前位置:网站首页>How to determine whether an array contains an element
How to determine whether an array contains an element
2022-07-04 05:42:00 【_ Virgo programmer's daily life】
Use findIndex
Definition and Usage :
findIndex() Method returns a test condition passed in ( function ) The first element position of the qualified array .
There are two points to pay attention to :
- When an element in an array tests a condition, it returns true when , findIndex() Returns the index position of a qualified element , Subsequent values do not call the execute function . Example 2 Is a good illustration , Even in the back 666 and 66 Greater than 50, But it only found 99, The following loop will not be executed .
- If no eligible element returns -1
example 1:
let allList=[1,2,3,4,5];
let d = allList.findIndex(item=>item==5) //4.
example 2:
var arr2 = [1,18,2,99,666,44,66];
var flag2 = arr2.findIndex(item => {
return item > 50;
});
console.log(flag2) // 3
find Method : Find out the qualified elements in the elements
let allList=[{
id:1,name:' Winter rain '},{
id:2,name:" Wintersweet "}];
let d = allList.find(item=>item.id==1)
console.log(d);// { id: 1, name: ' Winter rain ' }
let allList=[{
id:1,name:' Winter rain '},{
id:2,name:" Wintersweet "}];
let d = allList.find(item=>item.id==5)
console.log(d);//undefined
边栏推荐
- 19. Framebuffer application programming
- Online shrimp music will be closed in January next year. Netizens call No
- input显示当前选择的图片
- 如何获取el-tree中所有节点的父节点
- 509. Fibonacci number, all paths of climbing stairs, minimum cost of climbing stairs
- Just do it with your hands 7 - * project construction details 2 - hook configuration
- 如何判断数组中是否含有某个元素
- 每周小结(*63):关于正能量
- Thread pool: use thread pool to optimize query speed
- Etcd database source code analysis - initialization overview
猜你喜欢

Principle and practice of common defects in RSA encryption application

VB.net 简单的处理图片,黑白(类库——7)

Steady! Huawei micro certification Huawei cloud computing service practice is stable!

js arguments参数使用和详解
![[high concurrency, high performance and high availability of massive data MySQL practice-7] - memory data drop disk](/img/b9/cf4db4f8a5d2ef3fb344258f0e30f5.jpg)
[high concurrency, high performance and high availability of massive data MySQL practice-7] - memory data drop disk

Actual cases and optimization solutions of cloud native architecture

Programmers don't talk about morality, and use multithreading for Heisi's girlfriend

Arc135 C (the proof is not very clear)

How to configure static IP for Kali virtual machine

【QT】制作MyComboBox点击事件
随机推荐
HMS v1.0 appointment.php editid参数 SQL注入漏洞(CVE-2022-25491)
VB.net 简单的处理图片,黑白(类库——7)
(4) Canal multi instance use
1480. Dynamic sum of one-dimensional array
724. 寻找数组的中心下标
Arc135 a (time complexity analysis)
Flink1.13 basic SQL syntax (II) join operation
Excel comparator
Basic concept of bus
Wechat applet +php realizes authorized login
Character types of C language
[interested reading] advantageous filtering modeling on long term user behavior sequences for click through rate pre
Configure cross compilation tool chain and environment variables
Introduction to AMBA
FreeRTOS 中 RISC-V-Qemu-virt_GCC 的 锁机制 分析
[paper summary] zero shot semantic segmentation
VB.net 调用FFmpeg简单处理视频(类库——6)
Arc135 C (the proof is not very clear)
每周小结(*63):关于正能量
(4) Canal multi instance use