What is Map.has() function in JavaScript ?

What is Map.has() function in JavaScript ?

Image - Educative IO

The has() function of the map object accepts a key in string format and returns a boolean value of true if the specified key exists. Otherwise, the function returns false.

[ Map : Map is data structure in JavaScript that allows the storage of [key, vaule] pairs where any value can be used as either a key or value.]

Syntax :

mapObject.has(key)

The has() function takes a key in the string format. I returns a boolean value that indicates the presence of that key in the Map Object.

Example :

var mapObject = new Map([['a',1],['b',2],['c',3]]);

// checking for a key that exists in map
// return true
console.log(mapObject.has('b'));

// checking for a key that does not exist in map
// return false
console.log(mapObject.has('w'));