JavaScript SS6, Maps and Sets

0
516
JavaScript-SS6,-Maps-and-Sets---tinoshare.com
JavaScript-SS6,-Maps-and-Sets---tinoshare.com

JavaScript is evolving into one of the languages ​​of reference. Language Version 6 includes many new features, including new data types like Map (Map) and Seth (Set) which were still missing. Maps are responsible for defining data structures key / value sets while gathering a group of non-repeating elements.

Maps

We will build a map with SS6:

1
2
3
4
5
6
7
8
9
10
eleven
var map = new Map ();
var dni1 = {id: 1}, {id = dni2: 2};
mapa.set (dni1, "john" );
mapa.set (dni2, "maria" );
console.log (mapa.get (dni1));
          

As you can see it has been used as a key ID and name of the person as a value. The set method to populate the map and assign a key / value pair, the get method to pass the key as a parameter and get the stored name is used.

Map

Sets

The sets defined lists of items not repeated in the following code there are three people who are added to the set, the last one is repeated and the assembly is limited to two elements:

1
2
3
4
5
6
7
8
var set = new Set ();
var person1 = {person: "pedro" };
var person2 = {person: "angel" };
conjunto.add (person1) .add (person2) .add (person2);
console.log (conjunto.size);
              

Set

NO COMMENTS

LEAVE A REPLY

*