ES6's new method to achieve array deduplication

Two useful new things have been added to ES6, set and Array.from.

A set is a new data structure that can receive an array or an array-like object and automatically deduplicate duplicate items in it.

Here we can see that duplicate items have been removed, including NaNs. Under normal circumstances, NaN === NaN returns false, but in the set, it can also help you to remove the weight, which is amazing.

But as you can see here, set returns an object, but what we want is an array.

This time, it's time for Array.from to appear. Its function is to convert array-like objects and iterable objects into arrays.

This time we look at it again, it has become an array.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325928010&siteId=291194637