How to realize Array de-duplication by Javascript
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.