Learn some es6:map.

Source: Internet
Author: User

Map: Initialize:

Const MAPSIZE = (new Map ()). Size; mapsize:0

Const PAIR1 = [1, ' one '];
Const PAIR2 = [2, ' both '];

Const MAP = new Map ([Pair1, Pair2]); New Map (). Set (... pair1). Set (... pair2);

Whichever is the last set value:

Const PAIR1 = [1, ' one '];
Const PAIR2 = [1, ' Uno '];
Const PAIR3 = [1, ' eins '];
Const PAIR4 = [2, ' both '];
Const MAP = new Map ([Pair1, Pair2, Pair3, PAIR4]); New Map (). Set (... pair3). Set (... pair4);

Let map = new map ();
Const OBJ = {x:1, y:2};
Const KEYS = Object.keys (obj);
Keys.foreach (key = Map.set (key, Obj[key]));

Set, GET, has:

Let map = new map ();
Map.set (' key ', ' value '); Set can be used with OH
Const VALUE = map.get (' key ');

You can use anything to make a key OH:

Let map = new map ();
Const OBJ = {};
Map.set ({}, ' object is key ');

There is also the has method:

Let map = new map ([[' Key ', ' VALUE ']]);
Const HASKEY = Map.has (' key ');

Keys and Values method:

Let map = new map ();
Map.set (1, ' one '). Set (2, ' one ');
Assert.deepequal ([... Map.keys ()], [+]);
Assert.deepequal ([... map.values ()], [' One ', ' both ']);

Learn some es6:map.

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.