{"id":2458,"date":"2022-07-24T19:47:07","date_gmt":"2022-07-24T19:47:07","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=2458"},"modified":"2022-07-24T19:47:08","modified_gmt":"2022-07-24T19:47:08","slug":"javascript-map-has","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/javascript-map-has\/","title":{"rendered":"JavaScript Map has() Method"},"content":{"rendered":"<p style=\"text-align: center;\"><strong>Checking if the Map has the specified key (has method)<\/strong><\/p>\n<p>Now, let&#8217;s have a look at another method, which is going to help us find whether or not, some key is there on the map, associated with some value. So, we are going to give some key name as input, and then it is going to return true if the key is there, and it associates to some value, and false otherwise.<\/p>\n<h3 style=\"text-align: center;\">JavaScript Map has() Method<\/h3>\n<p>Here, the method that we are going to use, is the has method. In short, we are trying to check whether or not the map has that key.<\/p>\n<p>Let&#8217;s now have a look at a simple program, through which, we can simply understand the use of the has method.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1786 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/06\/Checking-if-the-Map-has-the-specified-key-has-method.jpg\" alt=\"\" width=\"1301\" height=\"284\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/06\/Checking-if-the-Map-has-the-specified-key-has-method.jpg 1301w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/06\/Checking-if-the-Map-has-the-specified-key-has-method-300x65.jpg 300w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/06\/Checking-if-the-Map-has-the-specified-key-has-method-1024x224.jpg 1024w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/06\/Checking-if-the-Map-has-the-specified-key-has-method-768x168.jpg 768w\" sizes=\"auto, (max-width: 1301px) 100vw, 1301px\" \/><br \/>\nIf we try to run the above program into the browser, the output comes out to be true, since key 1 is there in the Map, associated with some value. Otherwise, it is going to return false. Have a look at the below program as well, where, we are giving such a key, which is not there on the Map.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1787 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/06\/Checking-if-the-Map-has-the-specified-key-has-method-1.jpg\" alt=\"\" width=\"932\" height=\"182\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/06\/Checking-if-the-Map-has-the-specified-key-has-method-1.jpg 932w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/06\/Checking-if-the-Map-has-the-specified-key-has-method-1-300x59.jpg 300w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/06\/Checking-if-the-Map-has-the-specified-key-has-method-1-768x150.jpg 768w\" sizes=\"auto, (max-width: 932px) 100vw, 932px\" \/><\/p>\n<p>As you can see, this time, we are passing such a key to the has method, which is not there at all. In this case, the output comes out to be false. You can try having a look at the output as well.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Checking if the Map has the specified key (has method) Now, let&#8217;s have a look at another method, which is going to help us find whether or not, some key is there on the map, associated with some value. So, we are going to give some key name as input, and then it is going [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[14,15],"class_list":{"0":"post-2458","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-javascript-tutorial","7":"tag-javascript","8":"tag-javascript-tutorial"},"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/2458","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/comments?post=2458"}],"version-history":[{"count":2,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/2458\/revisions"}],"predecessor-version":[{"id":2501,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/2458\/revisions\/2501"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=2458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=2458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=2458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}