var arr=[1,2,1,3,2,4,5,1,3]; var setarr=New Set (arr); var newarr=[];setarr.foreach (function(e) { newarr.push (e);}); Console.log (NEWARR);
Set is the concept of a new set proposed in ES6, similar to the array arr, which is also not just a numeric type, other types of data such as strings are also supported, set has an array of different attributes is that duplicate elements are not valid in the collection, so an Using Set.add to add to this set automatically implements the step of de-weight.
The following are Set all supported operations:
new Set: Creates a new, empty Set .
new Set(iterable): Extracts elements from any data that can be traversed to construct a new collection.
set.size: Gets the size of the collection, which is the number of elements in it.
set.has(value): Returns a Boolean value that determines whether the specified element is contained in the collection.
set.add(value): Add an element. If it is duplicated, it does not produce an effect.
set.delete(value): Deletes an element. If it does not exist, it does not produce an effect. .add()and .delete() will return the collection itself, so we can use the chain syntax.
set[Symbol.iterator](): Returns a new iterator that iterates through the entire collection. In general, this method is not called directly, because it actually enables the collection to be traversed, that is to say, we can write directly, and for (v of set) {...} so on.
set.forEach(f): Just explain it in code, it's like a for (let value of set) { f(value, value, set); } shorthand, an array-like .forEach() method.
set.clear(): Empties the collection.
set.keys(), set.values() and set.entries() returns various iterators, which are provided for compatibility Map
This article transferred from: http://www.cnblogs.com/weblv/p/5192178.html
Using set to achieve de-weight