Map in JavaScript

Hello Readers!

I am here to share my knowledge about Map object of JavaScript.Actually,Map is builtIn object in the JavaScript .

The Definition of Map in JavaScript is like : Map is an object in JavaScript that contains key-value pairs .It bas ability to remember the original insertion order of the keys.

Syntax: const myMap=new Map();

const fruits = new Map(); fruits.set(1,"Apple"); fruits.set(2,"Orange"); fruits.set(3,"Pear"); console.log(fruits)//Map { 1 => 'Apple', 2 => 'Orange', 3 => 'Pear' }

Map has many properties and methods like set,get,side,clear. So,lets cover the properties and methods in detail .

  1. set : It is used to set key-value pair in the map.

  2. new : It is used to create new Map.

  3. side : It gives size of the map.

  4. clear : It remove all the elements from the map.

  5. delete : It deletes a particular element from Map by key.

  6. get : It returns particular element from rhe Map.

  7. has: It asks question whether the particular element present in the Map or not.

  8. forEach : It is used iterate over the map.

  9. keys : It returns element of keys.

  10. values : It returns element of values.

  11. enteries : It returns the elements of both keys and value.

Here is the example code :

const fruits = new Map(); fruits.set(1,"Apple"); fruits.set(2,"Orange"); fruits.set(3,"Pear"); console.log(fruits) console.log(fruits.size) //3 console.log(fruits.get(1)) // Apple console.log(fruits.has("papaya"))// false

So,We are coming of the ending of the blogs.We will meet in other blogs.