当前位置:网站首页>JS takes out the same elements in two arrays
JS takes out the same elements in two arrays
2022-04-23 03:26:00 【Open the door of the world】
Achieve the goal
Commodity search , Need to meet name search and id Search for . Name search , Is the direct interface data
. however id Search complete , You need to show the corresponding products
. So we need to id Make a comparison
, Make sure that the input id There are goods
. After all, you can't manually input 100% correctly , So the program needs to deal with
- Find the same element
let arr1 = [1, 2, 5];
let arr2 = [1, 3, 4, 2];
function compare(arr1, arr2) {
return arr1.filter((v) => {
return arr2.includes(v);
});
}
console.log(compare(arr1, arr2)); // [1, 2] Find the same element
except includes You can also use indexOf
let arr1 = [1, 2, 5];
let arr2 = [1, 3, 4, 2];
function compare(arr1, arr2) {
return arr1.filter((v) => {
return arr2.indexOf(v) !== -1;
});
}
console.log(compare(arr1, arr2));
版权声明
本文为[Open the door of the world]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220619451210.html
边栏推荐
- Peut recevoir plusieurs paramètres de type de données - paramètres variables
- C abstract class
- WinForm allows the form form to switch between the front and active states
- Visual programming - drawing assignment
- Initial experience of talent plan learning camp: communication + adhering to the only way to learn open source collaborative courses
- IDEA查看历史记录【文件历史和项目历史】
- Codeforces Round #784 (Div. 4)题解 (第一次AK cf (XD
- Generate QR code through zxing
- Configure automatic implementation of curd projects
- Unity games and related interview questions
猜你喜欢
【VS Code】解决jupyter文件在vs code中显示异常的问题
Use of ADB command [1]
Super easy to use [general excel import function]
[mock data] fastmock dynamically returns the mock content according to the incoming parameters
. net webapi access authorization mechanism and process design (header token + redis)
Test questions and some space wars
Charles uses three ways to modify requests and responses
Data mining series (3)_ Data mining plug-in for Excel_ Estimation analysis
Iotos IOT middle platform is connected to the access control system of isecure center
Optimization of especially slow startup in idea debugging mode
随机推荐
Web Course Design - his system
研讨会回放视频:如何提升Jenkins能力,使其成为真正的DevOps平台
Cefsharp stores cookies and reads cookies
"Visual programming" test paper
超好用的【通用Excel导入功能】
2022 团体程序设计天梯赛 模拟赛 L2-1 盲盒包装流水线 (25 分)
Visual programming - Experiment 1
打卡:4.23 C语言篇 -(1)初识C语言 - (12)结构体
Supersocket is Used in net5 - command
Comprehensive calculation of employee information
IOTOS物联中台对接海康安防平台(iSecure Center)门禁系统
MySQL之explain关键字详解
File upload vulnerability summary and upload labs shooting range documentary
Codeforces Round #784 (Div. 4)题解 (第一次AK cf (XD
2022 团体程序设计天梯赛 模拟赛 L1-7 矩阵列平移 (20 分)
Problem a: face recognition
Experiment 5 components and event handling
Five tips for cross-border e-commerce in 2022
12.<tag-链表和常考点综合>-lt.234-回文链表
The fourth operation