C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Map has() methodThe JavaScript map has() method indicates whether the Map object contains the specified key. It returns true if the specified key is present, otherwise false. SyntaxThe has() method is represented by the following syntax: mapObj.has(key) Parameterkey - It represents the key to be searched. ReturnA Boolean value. JavaScript Map has() method exampleHere, we will understand has() method through various examples. Example 1Let's see an example to determine whether the map object contains the specified key. <script> var map=new Map(); map.set(1,"jQuery"); map.set(2,"AngularJS"); map.set(3,"Bootstrap"); document.writeln(map.has(2)); </script> Output: true Example 2Let's see one more example to determine whether the map object contains the specified key. <script> var map=new Map(); map.set(1,"jQuery"); map.set(2,"AngularJS"); map.set(3,"Bootstrap"); document.writeln(map.has(5)); </script> Output: false Example 3Let's see the result when has() method is used without specifying key. <script> var map=new Map(); map.set(1,"jQuery"); map.set(2,"AngularJS"); map.set(3,"Bootstrap"); document.writeln(map.has()+"<br>"); document.writeln(map.has("jQuery")); </script> Output: false false
Next TopicJavaScript Math
|