Map
Map
Is the structure of a set of key-value pairs with extremely fast lookup speeds.
var m = new Map([[‘Michael‘, 95], [‘Bob‘, 75], [‘Tracy‘, 85]]);m.get(‘Michael‘); // 95
Set
Set
and Map
similar, is also a set of keys, but does not store value. Since key cannot be duplicated, therefore, Set
there is no duplicate key in the.
To create one Set
, you need to provide one Array
as input, or create a null directly Set
:
var s1 = new Set(); // 空Setvar s2 = new Set([1, 2, 3]); // 含1, 2, 3
Traversal Array
can take the subscript loop, traverse Map
and Set
cannot use subscript. In order to unify collection types, the ES6 standard introduces new iterable
types Array
, Map
and Set
all of them belong to iterable
types.
A iterable
collection with a type can traverse through a new for ... of
loop.
for ... of
The loop is the new syntax introduced by ES6
JS Map and set