当前位置:网站首页>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
边栏推荐
- Must see, time series analysis
- Technology implementation and Architecture Practice
- Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?
- 实例讲解将Graph Explorer搬上JupyterLab
- Create your own NFT collections and publish a Web3 application to show them (Introduction)
- R语言ggplot2可视化:可视化折线图、使用labs函数为折线图添加自定义的Y轴标签信息(customize y axis label)
- 创建您自己的NFT集合并发布一个Web3应用程序来展示它们(介绍)
- ACM mm 2022 video understanding challenge video classification track champion autox team technology sharing
- R语言使用epiDisplay包的tableStack函数制作统计汇总表格(基于目标变量分组的描述性统计、假设检验等)、不设置by参数则计算数据框指定数据列范围的基础描述性统计信息
- Stanford, salesforce|maskvit: masked vision pre training for video prediction
猜你喜欢

创建您自己的NFT集合并发布一个Web3应用程序来展示它们(介绍)

Li Kou daily question - Day 32 -589 N × Preorder traversal of tree

Intensive cultivation of channels for joint development Fuxin and Weishi Jiajie held a new product training conference

What if the reliability coefficient is low? How to calculate the reliability coefficient?

Leetcode-128 longest continuous sequence

Lumiprobe Lumizol RNA 提取试剂解决方案

How to manage 1000 anchors by one person?

Improve yolov5 with gsconv+slim neck to maximize performance!

How to find customers for investment attraction in industrial parks

Lumiprobe 双功能交联剂丨Sulfo-Cyanine5 双-NHS 酯
随机推荐
How to realize the applet in its own app to realize continuous live broadcast
R language ggplot2 visualization: visualize the line graph and add customized Y-axis label information to the line graph using the labels function
GameFramework食用指南
How to operate technology related we media well?
Example explanation: move graph explorer to jupyterlab
Lumiprobe bifunctional crosslinker sulfo cyanine 5 bis NHS ester
R language epidisplay package ordinal or. The display function obtains the summary statistical information of the ordered logistic regression model (the odds ratio and its confidence interval correspo
精耕渠道共谋发展 福昕携手伟仕佳杰开展新产品培训大会
JS find the next adjacent element of the number in the array
1. "Create your own NFT collections and publish a Web3 application to show them." what is NFT
ES6数组去重的三个简单办法
AI training speed breaks Moore's law; Song shuran's team won the RSS 2022 Best Paper Award
Database foundation: select basic query statement
R language uses the aggregate function of epidisplay package to divide numerical variables into different subsets based on factor variables, and calculate the summary statistics of each subset
[Chongqing Guangdong education] basic psychology reference materials of Tianjin Normal University
R语言使用dplyr包的transmute函数计算dataframe数据中的指定数据列的移动窗口均值、使用ggplot2包可视化移动均值与原始数据的折线图
Leetcode203 移除链表元素
How does factor analysis calculate weights?
每周推薦短視頻:警惕“現象”與“問題”相互混淆
Leetcode-83 delete duplicate elements in the sorting linked list