Sunday 21 October 2018

JavaScript: Map.prototype.has(key): Check for existence of key

Map.prototype.has(key)
This method returns true, if the map cotains given key, else false.

Find the below working application.

HelloWorld.js
var countriesMap = new Map();

countriesMap.set("Bahrain", "Manama");
countriesMap.set("Cameroon", "Yaounde");
countriesMap.set("Norway", undefined);
countriesMap.set("India", "New Delhi");

console.log("Is countriesMap has Norway : " + countriesMap.has("Norway"));
console.log("Is countriesMap has India : " + countriesMap.has("India"));
console.log("Is countriesMap has Australia : " + countriesMap.has("Australia"));


Output
Is countriesMap has Norway : true
Is countriesMap has India : true
Is countriesMap has Australia : false




Previous                                                 Next                                                 Home

No comments:

Post a Comment