当前位置:网站首页>Array, string de duplication
Array, string de duplication
2022-07-28 13:13:00 【Pig Xiaoyong】
Array weight removal
Method 1 :
Extension operators and Set The combination of structure , You can remove duplicate members of the array .
// Remove duplicate members of the array
[...new Set(array)]
let arr = [3, 5, 2, 2, 5, 5];
let unique = [...new Set(arr)];
// [3, 5, 2]
Method 2 :
Array.from Method can Set Structure to array .
const items = new Set([1, 2, 3, 4, 5]);
const array = Array.from(items);

This provides another way to remove duplicate members of an array .
function dedupe(array) {
return Array.from(new Set(array));
}
dedupe([1, 1, 2, 3]) // [1, 2, 3]
String de duplication
Remove duplicate characters from the string .
[...new Set('ababbc')].join('')
// "abc"
边栏推荐
- Science heavyweight: AI design protein has made another breakthrough, and it can design specific functional proteins
- 《TiDB 6.x in Action》发布,凝聚社区集体智慧的 6.x 实践汇总!
- Databinding+livedata can easily realize skin changing without restart
- Understanding of vite2
- [error prone points of C language] Part 4: detailed rules for storing structures in memory
- 2020-12-13
- Huawei cloud Gao Hongxia: CBC microservice code Reconstruction & independent release practice
- Brother bird talks about cloud native security best practices
- 面试必问,敲重点!讲一下 Android Application 启动流程及其源码?
- Jetpack Compose 完全脱离 View 系统了吗?
猜你喜欢

Stepless dimming colorful RGB mirror light touch chip-dlt8s12a-jericho

Transaction of MySQL underlying principle (2)
![[embedded C foundation] Part 6: super detailed explanation of common input and output functions](/img/eb/69264bc0d8e9349991b7b9e1b8ca22.png)
[embedded C foundation] Part 6: super detailed explanation of common input and output functions

如何在 TiDB Cloud 上使用 Databricks 进行数据分析 | TiDB Cloud 使用指南

【嵌入式C基础】第6篇:超详细的常用的输入输出函数讲解

SSH port forwarding (Tunneling Technology)

Introduction to border border attribute

Which big model is better? Openbmb releases bmlist to give you the answer!

Remove the plug-in of category in WordPress link

Machine learning practice - neural network-21
随机推荐
【嵌入式C基础】第7篇:C语言流程控制详讲
【嵌入式C基础】第3篇:常量和变量
10、 Kubernetes scheduling principle
What if the win11 folder cannot be opened
Led aquarium lamp touch chip-dlt8t02s-jericho
【嵌入式C基础】第6篇:超详细的常用的输入输出函数讲解
【嵌入式C基础】第2篇:进制转换与BCD编码
机器学习基础-集成学习-13
Machine learning practice - decision tree-22
机器学习实战-决策树-22
子线程更新UI全解
What if the right button of win11 start menu doesn't respond
What if win11 cannot recognize Ethernet
Smart touch screen LCD bathroom mirror light touch chip-dlt8t02s-jericho
什么是事务及数据库的优化方法
FutureWarning: Indexing with multiple keys (implicitly converted to a tuple of keys) will be depreca
[embedded C foundation] Part 2: binary conversion and BCD coding
[matlab] IIR filter
How to use databricks for data analysis on tidb cloud | tidb cloud User Guide
Low code: reduce technical capability requirements and improve software development efficiency