当前位置:网站首页>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
边栏推荐
- Quartz. Www. 18fu Used in net core
- ThreadLocal 测试多线程变量实例
- 2022 团体程序设计天梯赛 模拟赛 L1-7 矩阵列平移 (20 分)
- 超好用的Excel异步导出功能
- Chapter 9 of C language programming (fifth edition of Tan Haoqiang) analysis and answer of exercises for users to establish their own data types
- 2022g2 boiler stoker examination question bank and online simulation examination
- A comprehensive understanding of static code analysis
- MySQL query specifies that a row is sorted to the first row
- Configure automatic implementation of curd projects
- Codeforces round 784 (Div. 4) (AK CF (XD) for the first time)
猜你喜欢

Using swagger in. Net5

2022 团体程序设计天梯赛 模拟赛 L2-3 浪漫侧影 (25 分)

2022 group programming ladder simulation l2-1 blind box packaging line (25 points)

浅学一下I/O流和File类文件操作
![Use of ADB command [1]](/img/e6/fb8fd6956c226f75b831f8eb46277f.png)
Use of ADB command [1]

QT learning summary

Codeforces Round #784 (Div. 4)題解 (第一次AK cf (XD

二进制文件版本控制工具选择难?看完这篇你会找到答案

为什么BI对企业这么重要?

Test questions (2)
随机推荐
The website JS in. Net core cefsharp chromium WebBrowser calls the C method in winfrom program
General test technology [II] test method
MySQL query specifies that a row is sorted to the first row
L3-011 直捣黄龙 (30 分)
Log4net is in Net core usage
Advanced sorting - fast sorting
IDEA查看历史记录【文件历史和项目历史】
Chapter 8 of C language programming (fifth edition of Tan Haoqiang) is good at using pointer exercises to analyze and answer
Eight elder brothers chronicle [4]
Flink实时数仓项目—DWS层设计与实现
Docker拉取mysql并连接
C interface
Docker pulls MySQL and connects
socket编程 send()与 recv()函数详解
Explanation keyword of MySQL
Translation of l1-7 matrix columns in 2022 group programming ladder Simulation Competition (20 points)
"Visual programming" test paper
Utgard connection opcserver reported an error caused by: org jinterop. dcom. common. JIRuntimeException: Access is denied. [0x800
Oracle query foreign keys contain comma separated data
JS recursive tree structure calculates the number of leaf nodes of each node and outputs it