JS Map and set

Source: Internet
Author: User
Tags iterable

Map

MapIs 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

Setand 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 ... ofThe loop is the new syntax introduced by ES6

JS Map and set

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.