Home » Javascript10 July 2018

Javascript: Map object & Loop

A Javascript Map object holds the key-value pairs of elements. An array or any other iterable object can be passed to the Map.

– Map is a new data structure introduced in JavaScript ES6.
– It’s an alternative to JavaScript Object for storing key/value pairs.
– It has useful methods for iteration over the key/value pairs.

Create a Map object in Javascript

Get the full content of the Map

Get value of the Map using key

Get size of the Map

Check key exists in Map

Get keys of the Map object

Get values of the Map object

Get elements of the Map

Print key value pairs

Print only keys of the Map

Print only values of the Map

Iterating Map object with forEach() function

Add a new element to the Map

Delete an element from the Map

Delete all key-value pairs of the Map

CONVERT ARRAY INTO MAP & CONVERT MAP INTO ARRAY

Creating Map object with multi-dimensional array as iterable

Convert Array object into Map object

Convert Map into Array

Map is similar to Object as both have key-value pairs.
However, iteration is easier in Map as compared to Object.
Map can be directly iterated whereas you have to obtain the keys of an Object to iterate it.
The other difference is that the keys of Object has to be String or Symbol but for Map, it can be anything like Object, String, Function, etc.

Hope this helps. Thanks.

Javascript

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed

Comments are closed.