Get the App
SLTechnology News&Howtos  ›  Network Security  › 

How to realize Array de-duplication by Javascript

Shulou Source: shulou.com Published: 2022-05-31 16:13:25 10月03日 Update

This article will explain in detail how to achieve array de-duplication in Javascript. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Array deduplication 1, from () superposition new Set () method

The from method can be used directly for the deduplication of a string or numeric array.

Var plants = ['Saturn',' Earth', 'Uranus',' Mercury', 'Venus',' Earth', 'Mars',' Jupiter']; var uniquePlants = Array.from (new Set (plants)); console.log (uniquePlants); / / ['Saturn',' Earth', 'Uranus',' Mercury', 'Venus',' Mars', 'Jupiter'] 2, spread operator (…)

The extension operator is a major innovation of ES6, and there are many powerful features.

Var plants = ['Saturn',' Earth', 'Uranus',' Mercury', 'Venus',' Earth', 'Mars',' Jupiter']; var uniquePlants = [. New Set (plants)]; console.log (uniquePlants) / / ['Saturn',' Earth', 'Uranus',' Mercury', 'Venus',' Mars', 'Jupiter'] this is the end of the article on "how to achieve array de-duplication in Javascript". I hope the above content can be helpful to you so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Arrays articles methods more good practical powerful content functions characters strings operators numeric values articles knowledge operators references overlays help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Microsoft Shulou Technology Redmi Apple