How to realize Array de-duplication by js
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!