Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize Array de-duplication by js

Shulou Source: shulou.com Published: 2022-06-01 05:54:45 11月01日 Update

Editor to share with you how to achieve js array de-weight, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

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'] these are all the contents of the article "how to remove duplicates in js". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Arrays articles content methods powerful less functional most characters strings operators numeric values more knowledge industry information information channels operators channels references Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi MySQL Docker Shulou Tech Info Apple