[Tips + Javascript] Make a unique array
2024-08-28 17:22:40
To make an array uniqued, we can use Set() from Javascript.
const ary = ["a", "b", "c", "a", "d", "c"];
console.log(new Set(ary));
We can see that all the duplicated value have been removed, now the only thing we need to do is convert Set to Array.
So we have Array.from:
const ary = ["a", "b", "c", "a", "d", "c"];
const res = uniqueArray(ary);
console.log(res); function uniqueArray(ary) {
return Array.from(new Set(ary));
}
Or even shorter:
const ary = ["a", "b", "c", "a", "d", "c"];
const res = uniqueArray(ary);
console.log(res); function uniqueArray(ary) {
return [...new Set(ary)];
}
Whichever you prefer.
最新文章
- Hibernate SQL方言 (hibernate.dialect) Spring配置文件applicationContext.xml
- MVC中Action的执行过程
- 转:MVC单表多按钮提交
- hibernate manytoone中的lazy EAGER
- Hive on Spark运行环境搭建
- Sql Server 远程过程调用失败
- 【LeetCode练习题】First Missing Positive
- 定向爬虫之爬一爬各个学校新闻的认识(【1】对Url的认识)
- JavaScript变量存储浅析
- testng及JMeter使用之初体验
- Taurus.MVC 2.3 开源发布:增强属性Require验证功能,自带WebAPI文档生成功能
- python3 - 文本读音器
- Linux cached过高问题
- 安卓开发_深入理解Content Provider
- leecode第一百四十二题(环形链表II)
- JS面试典型常见问题与解答
- office 2007,SQL Server 2008,VS2010安装步骤
- Hadoop框架
- Java中Date与String的相互转换
- Java的基本类型
热门文章
- 扩展欧几里得(ex_gcd),中国剩余定理(CRT)讲解 有代码
- js 数组遍历
- 使序列有序的最少交换次数(minimum swaps)
- Strlcpy和strlcat——一致的、安全的字符串拷贝和串接函数【转】
- 链表各种操作及其实现方法(c实现)
- DropZone图片上传控件的使用
- python中函数和生成器的运行原理
- 解决svn 异常:svn: E155027: Tree conflict can only be resolved to working state; {0} not resolved
- OutputDebugString方便格式化WIN32封装
- (22)C#windows打包部署