惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Hacker News
The Hacker News
C
Cisco Blogs
P
Privacy & Cybersecurity Law Blog
Cloudbric
Cloudbric
S
Security Affairs
PCI Perspectives
PCI Perspectives
The Last Watchdog
The Last Watchdog
AWS News Blog
AWS News Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
N
News and Events Feed by Topic
W
WeLiveSecurity
T
Tenable Blog
L
LINUX DO - 最新话题
T
Tor Project blog
Help Net Security
Help Net Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Proofpoint News Feed
爱范儿
爱范儿
O
OpenAI News
Hacker News - Newest:
Hacker News - Newest: "LLM"
Y
Y Combinator Blog
I
Intezer
C
Check Point Blog
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
Google DeepMind News
Google DeepMind News
S
Securelist
P
Privacy International News Feed
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
量子位
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
T
Threat Research - Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Scott Helme
Scott Helme
H
Help Net Security
Vercel News
Vercel News
云风的 BLOG
云风的 BLOG
Spread Privacy
Spread Privacy
Know Your Adversary
Know Your Adversary
I
InfoQ
TaoSecurity Blog
TaoSecurity Blog
Blog — PlanetScale
Blog — PlanetScale
N
News | PayPal Newsroom
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes

博客园 - 雪莉06

antd vue 树形表格 vue2 jeecgBoot keepalive 解决方案 vue中实现页面全屏和指定元素全屏 screenfull全屏组件的基本使用 网页导出EXCEL格式数据,长数字变为科学计数法的解决方法 dedecms织梦自定义表单导出到excel的方法 织梦dede:arclist按最新修改排序orderby=pubdate无效的解决方法 vue-router报错:Uncaught (in promise) NavigationDuplicated {_name: ‘NavigationDuplicated‘, name: ‘Navig nvm的安装和使用(转) elementUI 的 input无法输入bug解决 vue数字翻牌效果 j-modal的 slot="footer" 失效 v-if判断页脚按钮 帝国CMS后台登录空白怎么办?如何修改成https element ui form表单 表格下嵌套动态表格,新增行,删除行 vue 父子组件传值报错:this.$emit is not a function 解决 dede列表页调用二三级导航栏(转载) a-table 鼠标滑过显示小手,当前行可点击(转载) echarts折线图使用dataZoom,切换数据时渲染异常,出现竖线bug vue里面修改title样式
ES6两个数组进行比较
雪莉06 · 2024-08-30 · via 博客园 - 雪莉06

在ES6中,可以使用扩展运算符...Array.prototype.includes方法来比较两个数组,并找出它们的不同元素。

const array1 = [1, 2, 3, 4, 5];
const array2 = [3, 4, 5, 6, 7];

// 找出在array1中而不在array2中的元素
const diff1 = array1.filter(item => !array2.includes(item));

// 找出在array2中而不在array1中的元素
const diff2 = array2.filter(item => !array1.includes(item));

console.log(diff1); // [1, 2]
console.log(diff2); // [6, 7]

如果数组中可能包含重复元素,并且希望得到的差异数组不包含重复项,可以在filter之后使用Set来去重:

const array1 = [1, 2, 2, 3, 4, 5];
const array2 = [3, 4, 4, 5, 6, 7];

const diff1 = [...new Set(array1.filter(item => !array2.includes(item)))];
const diff2 = [...new Set(array2.filter(item => !array1.includes(item)))];

console.log(diff1); // [1, 2]
console.log(diff2); // [6, 7]
以上代码展示了如何找出两个数组之间的差异。如果需要更复杂的比较逻辑,例如比较数组中对象的特定属性,可能需要使用更复杂的代码来实现。