当前位置:网站首页>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
边栏推荐
- Explanation keyword of MySQL
- Use of ADB command [1]
- Punch in: 4.23 C language chapter - (1) first knowledge of C language - (12) structure
- Flink real-time data warehouse project - Design and implementation of DWS layer
- 可以接收多种数据类型参数——可变参数
- EasyUI's combobox implements three-level query
- . net webapi access authorization mechanism and process design (header token + redis)
- [vs Code] solve the problem that the jupyter file displays exceptions in vs code
- Supersocket is Use in net5 - startup
- Initial experience of talent plan learning camp: communication + adhering to the only way to learn open source collaborative courses
猜你喜欢

C abstract class

New ORM framework -- Introduction to beetlsql

MySQL索引详解【B+Tree索引、哈希索引、全文索引、覆盖索引】

2022g2 boiler stoker examination question bank and online simulation examination

Unity basics 2

AWS from entry to actual combat: creating accounts
![[mock data] fastmock dynamically returns the mock content according to the incoming parameters](/img/1e/c4aad49d16fb21a19865ba75128e43.png)
[mock data] fastmock dynamically returns the mock content according to the incoming parameters

Huawei mobile ADB devices connection device is empty

File upload vulnerability summary and upload labs shooting range documentary

Optimization of especially slow startup in idea debugging mode
随机推荐
JSON related
Why is bi so important to enterprises?
The website JS in. Net core cefsharp chromium WebBrowser calls the C method in winfrom program
Do you really understand hashcode and equals???
Téléchargement en vrac de fichiers - téléchargement après compression
Fiddler use
MySQL installation pit
Unity Basics
Student achievement management
Generate QR code through zxing
Configuration table and page information automatically generate curd operation page
Codeforces Round #784 (Div. 4)題解 (第一次AK cf (XD
Top ten project management software similar to JIRA
Super easy to use asynchronous export function of Excel
MySql关键字GROUP_CONCAT,组合连接查询
Talent Plan 学习营初体验:交流+坚持 开源协作课程学习的不二路径
打卡:4.22 C语言篇 -(1)初识C语言 - (11)指针
Problem C: realize Joseph Ring with linked list
MySQL keyword group_ Concat, combined connection query
Comprehensive calculation of employee information