javascript - Merge multiple object values of array into 1
问题描述
This is my array:
[
'Ddy1QVOAO6SIvB8LfAE8Z0Adj4H3',
'hBwNVTlluaagZ5Fqd6f0Ws3Vxtn1',
'Ddy1QVOAO6SIvB8LfAE8Z0Adj4H3',
'Ddy1QVOAO6SIvB8LfAE8Z0Adj4H3'
]
If want to check, if it has similar objects then I want it to be merged into one and return me array as:
[
'Ddy1QVOAO6SIvB8LfAE8Z0Adj4H3',
'hBwNVTlluaagZ5Fqd6f0Ws3Vxtn1',
]
How is this possible in JavaScript or TypeScript?
解决方案
Use Set to remove duplicate values :
array = [ 'Ddy1QVOAO6SIvB8LfAE8Z0Adj4H3',
'hBwNVTlluaagZ5Fqd6f0Ws3Vxtn1',
'Ddy1QVOAO6SIvB8LfAE8Z0Adj4H3',
'Ddy1QVOAO6SIvB8LfAE8Z0Adj4H3' ];
var result = [...new Set(array)];
console.log(result);
推荐阅读
- swift - 带有 React-Native 的 Xcode Widget Extension 如何正确设置 @main
- javascript - DiscordJS / Canvas - 图像未从 URL 加载
- android - 应用已在 Play 商店发布但无法连接到 Admob
- javascript - 通过 chrome 扩展访问 Spring Secured API
- sql - 显示有条件的连续数据的 SELECT 语句
- java - Web 应用程序的 Java Oracle 数据库更改通知问题
- javascript - 如何使javascript函数在另一个内部和外部可见
- powerquery - 使用 Office 脚本和 Power Automate 刷新 Excel 工作簿 (Excel Online) 的所有查询和连接
- node.js - ExpressJS 4.x:简单地用变量渲染 index.html(就像在 Django 中一样)
- php - 我正在尝试将数据库中的所有列打印到水平表