当前位置:网站首页>Three simple methods of ES6 array de duplication
Three simple methods of ES6 array de duplication
2022-07-01 18:55:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
ES6 Three simple ways to remove duplicate arrays
Briefly, use ES6 Three ways to realize array de duplication .
The first one is : utilize Map Objects and arrays filter Method
Paste the relevant code
Printed results
By printing, we found that , It has really achieved the effect we want . Then let's explain briefly . 1.Map The object is ES6 Provide a new data structure , among has The way is to return a Boolean value , Indicates whether a value has the current Mp Among objects ,set The best way is to give Map Object settings key/value. 2.filter() Method to create a new array , The elements in the new array are checked by checking all the eligible elements in the specified array . So ,Map Object combination filter Method can achieve the effect of array de duplication ~
The second kind : utilize Set Objects and arrays Array.from Method
Also post relevant code snippets
Print the results after running
Simply speaking , The second method is simpler than the first . Let's also explain briefly . 1.Set yes ES6 New data structure , It's like an array , But there are no duplicate values in itself . 2.Array.from Method to convert two types of objects into real arrays : Array like objects (array-like object) Ergodic (iterable) The object of ( Include ES6 New data structure Set and Map). therefore set combination Array.from It can also achieve the effect of array de duplication . But here's the thing , Mainstream browsers are like Chrome,Firfox,Opera,Safari, Including Microsoft's Edge, All supported , But only IE Series does not support .
The third kind of : utilize Set+ Extension operator …
The third way can be said to be simpler Paste the relevant code
Results of running after printing
This is the use of ES6 There are three ways for new features to achieve array de duplication , The common advantage of these three methods is that the code is concise , about undefined and NaN It can also achieve the effect of weight removal ~~
If you have other ways, please share them ~
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/130837.html Link to the original text :https://javaforall.cn
边栏推荐
- 如何使用物联网低代码平台进行个人设置?
- 【快应用】Win7系统使用华为IDE无法运行和调试项目
- Five degrees easy chain enterprise app is newly upgraded
- R语言caTools包进行数据划分、scale函数进行数据缩放、class包的knn函数构建K近邻分类器、table函数计算混淆矩阵
- Li Kou daily question - Day 32 -1232 Dotted line
- Write an open source, convenient and fast database document query and generation tool with WPF
- Facebook聊单,SaleSmartly有妙招!
- OpenAI|视频预训练 (VPT):基于观看未标记的在线视频的行动学习
- Popular science: what does it mean to enter the kernel state?
- Qt中的QFile读写文件操作
猜你喜欢

Leetcode-160 intersecting linked list

Stanford, salesforce|maskvit: masked vision pre training for video prediction

毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?

Halcon image calibration enables subsequent image processing to become the same as the template image

How to manage 1000 anchors by one person?

ACM MM 2022视频理解挑战赛视频分类赛道冠军AutoX团队技术分享

Vidéos courtes recommandées chaque semaine: méfiez - vous de la confusion entre « phénomène » et « problème »

Image acquisition and playback of coaxpress high speed camera based on pxie interface

3、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》在本地铸造 NFT

创建您自己的NFT集合并发布一个Web3应用程序来展示它们(介绍)
随机推荐
Halcon图片标定,使得后续图片处理过后变成与模板图片一样
Li Kou daily question - Day 32 -589 N × Preorder traversal of tree
R语言ggplot2可视化:gganimate创建动态柱状图动画(gif)、在动画中沿给定维度逐步显示柱状图、enter_grow函数和enter_fade函数控制运动内插退出(渐变tweening)
Navicat Premium 15 永久破解和2021版本最新IDEA破解(亲测有效)
【快应用】text组件里的文字很多,旁边的div样式会被拉伸如何解决
Popular science: what does it mean to enter the kernel state?
How to find the optimal learning rate
Viewing the whole ecology of Tiktok from a macro perspective
1. "Create your own NFT collections and publish a Web3 application to show them." what is NFT
微服务大行其道的今天,Service Mesh是怎样一种存在?
Leetcode-160相交链表
GAMES202作业0-环境搭建过程&解决遇到的问题
Thread forced join, thread forced join application scenarios
毕业总结
How to realize the bottom layer of read-write lock in go question bank 16
解决方案:可以ping别人,但是别人不能ping我
Improve yolov5 with gsconv+slim neck to maximize performance!
How to realize the applet in its own app to realize continuous live broadcast
Livedata postvalue will "lose" data
Leetcode-128 最长连续序列