⊗jsSpMpInr 32 of 294 menu

Map collections in JavaScript

Map Collections are objects in which both primitives and objects can act as keys.

Let's try with an example. First, let's create a collection using the following command:

let map = new Map;

After that, elements can be added to the collection using the set method and received using the get method.

Let's try. Let's make two arrays as keys:

let arr1 = [1, 2]; let arr2 = [3, 4];

Let's assign some values to our keys:

map.set(arr1, 'data1'); map.set(arr2, 'data2');

And now read our values by the keys:

console.log(map.get(arr1)); console.log(map.get(arr2));

Let 3 arrays be given. Create a Map collection, make these arrays as keys of the collection, and some strings as values.

Let 3 objects and 3 arrays be given. Create a Mapcollection, make the objects as collection keys, and the corresponding arrays as values.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline