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 .
set : It is used to set key-value pair in the map.
new : It is used to create new Map.
side : It gives size of the map.
clear : It remove all the elements from the map.
delete : It deletes a particular element from Map by key.
get : It returns particular element from rhe Map.
has: It asks question whether the particular element present in the Map or not.
forEach : It is used iterate over the map.
keys : It returns element of keys.
values : It returns element of values.
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.