{"id":6691,"date":"2025-01-17T07:28:10","date_gmt":"2025-01-17T07:28:10","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=6691"},"modified":"2025-01-17T07:41:43","modified_gmt":"2025-01-17T07:41:43","slug":"how-to-check-if-key-exists-in-javascript-object","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/","title":{"rendered":"How to Check if Key Exists in JavaScript Object"},"content":{"rendered":"\n<p>JavaScript objects are popular data structures used widely by web developers these days. They allow you to store diverse data types in a compact manner as key-value pairs. They allow you to easily access data using keys. However, if you try to access a key that does not exist then web browser may return undefined or throw an error and may even stop code execution. So it is always recommended to check if key exists in JavaScript object before you try to access it. There are several ways to solve this problem using JavaScript alone. In this article, we will learn different ways to check if a key exists in JavaScript object.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#The_Problem\" >The Problem<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#Absent_Key_vs_Undefined_Value\" >Absent Key vs Undefined Value<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#How_to_Check_if_Key_Exists_in_JavaScript_Object\" >How to Check if Key Exists in JavaScript Object<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#1_Using_In_Operator\" >1. Using In Operator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#2_Using_hasOwnProperty\" >2. Using hasOwnProperty()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#3_Using_hasOwn\" >3. Using hasOwn()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#4_Using_Keys\" >4. Using Keys()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#5_Using_Double_Bang_Operator\" >5. Using Double Bang Operator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#6_By_accessing_elements_via_Brackets\" >6. By accessing elements via Brackets<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#7_By_accessing_elements_via_Objects\" >7. By accessing elements via Objects<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#8_Check_Multiple_Keys\" >8. Check Multiple Keys<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_Problem\"><\/span>The Problem<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Let us say you have the following JavaScript object.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var data = {'a':1,'b':2};<\/pre>\n\n\n\n<p>The above JS object contains two keys a and b. Let us say you try to access the value of key c which is not present in the above object.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log(data['c']); \/\/ prints undefined<\/pre>\n\n\n\n<p>In most modern web browsers like Chrome, the above code will return undefined value. <\/p>\n\n\n\n<p>If you use the object notation, it may even give error.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log(data.3); \/\/ gives error<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Absent_Key_vs_Undefined_Value\"><\/span>Absent Key vs Undefined Value<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Before we proceed, it is important to understand the difference between the absence of a key in a JS object and the key having undefined value assigned to it. When you try to access a key that doesn&#8217;t exist, web browser will return undefined value. If the key is present but assigned undefined value, when you try to assign such a key, even that will return undefined. So you cannot rely on value being undefined to determine whether the key exists or not.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Check_if_Key_Exists_in_JavaScript_Object\"><\/span>How to Check if Key Exists in JavaScript Object<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Now let us look at different ways to check if key exists in JavaScript object. Let us say you have the following object.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var data = {'a':1,'b':2, 3:3, 4: undefined};<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_In_Operator\"><\/span>1. Using In Operator<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The IN operator checks whether a key is present in a JS object. It returns true if the key is present, else it returns false. It is a very easy way to check if a key exists or not. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">'key' in object<\/pre>\n\n\n\n<p>Here is the code to check if key c is present in data or not.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log('c' in data); \/\/ returns false<\/pre>\n\n\n\n<p>Please note, while using IN operator, if your keys are strings, then you need to mention the key within quotes. Otherwise, you will get an error. But if you have numeric key, then you will get the same result, with or without quotes.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log(3 in data); \/\/ returns true<br>console.log('3' in data); \/\/ returns true<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_hasOwnProperty\"><\/span>2. Using hasOwnProperty()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Every JS object supports a built-in method hasOwnProperty() that accepts the key as an input argument and returns a Boolean value. It returns true if the key is present, else it returns false. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Object.hasOwnProperty(key);<\/pre>\n\n\n\n<p>Like in the case of IN operator, if you are looking for a string key, it needs to be within quotes. If you are looking for a numerical key, then you may or may not use quotes.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log(data.hasOwnProperty('c')); \/\/ returns false<br>console.log(data.hasOwnProperty('3')); \/\/ returns true<br>console.log(data.hasOwnProperty(3)); \/\/ returns true<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_hasOwn\"><\/span>3. Using hasOwn()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>There is another method hasOwn() that is available for Object prototype. It checks an object for a key and returns Boolean value. It returns true if the key exists and false if the key does not exist. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Object.hasOwn(object, key);<\/pre>\n\n\n\n<p>Here are a few examples to check if key c and 3 are present in the data object or not.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log(Object.hasOwn(data,'c'));  \/\/ returns false<br>console.log(Object.hasOwn(data,'3'));  \/\/ returns true<br>console.log(Object.hasOwn(data,3));    \/\/ returns true<\/pre>\n\n\n\n<p>In this case also, strings and alphanumeric keys need to be within quotes whereas numeric keys may or may not be within quotes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Using_Keys\"><\/span>4. Using Keys()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The Object prototype supports keys() function that accepts an object as input and returns an array of all keys present in the object. You can use it along with includes() function to check if a specific key is present or not in it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Object.keys(object_name).includes(key);<\/pre>\n\n\n\n<p>In the above code, Object.keys() returns an array of keys. Since every JS array supports includes() function, we can call it directly on the result of Object.keys(). Here are some examples to check if key exists in JS object using this method.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log(Object.keys(data).includes('c')); \/\/ prints false<br>console.log(Object.keys(data).includes('3')); \/\/ prints true<br>console.log(Object.keys(data).includes(3)); \/\/ prints false<\/pre>\n\n\n\n<p>In the above code, you will see that when we check if key=3 is present, it returns false, even though it is clearly present in the object. This is because Object.keys() returns an array of keys, where each key is present as a string, within quotes. So when we call includes() function on this array, you need to mention the key within quotes.<\/p>\n\n\n\n<p>In other words, when you use this method, always specify the key to be searched, within quotes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Using_Double_Bang_Operator\"><\/span>5. Using Double Bang Operator<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can also use double bang operator to check if the key exists or not. It returns true if the key exists, else it returns false. It also returns false, if the key exists but its value is undefined.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var data = {'a':1,'b':2,3:3,4:undefined};<br>console.log(!!data['c']); \/\/ prints false<br>console.log(!!data[3]);  \/\/ prints true<br>console.log(!!data[4]);  \/\/ prints false<\/pre>\n\n\n\n<p>In the above code, when we look for key c it returns false since the key is not present. When we look for key 3, it returns true since it is present. Lastly, when we look for key 4, it still returns false, since its value is set to undefined.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6_By_accessing_elements_via_Brackets\"><\/span>6. By accessing elements via Brackets<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Another way to directly check if a key is present or not is to check if its value is undefined. In this case, we directly access the element with desired key, using brackets. Here is the syntax for it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">object[key]==undefined<\/pre>\n\n\n\n<p>Here is an example to illustrate its use.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log(data['c']==undefined); \/\/ prints true<\/pre>\n\n\n\n<p>For numeric keys, you may or may not use quotes.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log(data['3']==undefined); \/\/ prints false<br>console.log(data[3]==undefined);  \/\/ prints false<\/pre>\n\n\n\n<p>As mentioned earlier, if any of the key has undefined value, then this method will return true.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var data = {'a':1,'b':2, 3:3, 4: undefined};<br>console.log(data[4] == undefined); \/\/ prints true<\/pre>\n\n\n\n<p>Please note, this solution will not work if the key is present but its value is set to undefined. In all other cases, it works much faster than above mentioned solutions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"7_By_accessing_elements_via_Objects\"><\/span>7. By accessing elements via Objects<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Similarly, you may also access keys using object notation and check if its value is undefined or not. This method works only if the key you are looking for starts with a character. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">object.key == undefined<\/pre>\n\n\n\n<p>Here is an example to check if keys c and 3 exist in data object.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var data = {'a':1,'b':2, 3:3, 4: undefined};<br>console.log(data.c==undefined); \/\/ prints true<br>console.log(data.'3'==undefined); \/\/ gives error<br>console.log(data.3==undefined); \/\/ gives error<br>console.log(data.4==undefined);  \/\/ gives error<br>console.log(data.c4==undefined); \/\/ prints true<\/pre>\n\n\n\n<p>Let us look at the above code in detail. The first equation prints true because key c is not present in the object. The second equation gives error because the object contains number 3 as key but we are looking for 3 within quotes. The third equation gives error even though 3 is one of the keys present in the object, because object notation supports only string keys. Fourth equation also gives error because 4 is not present as one of the keys. But the last equation prints true because the key you are looking for begins with a character.<\/p>\n\n\n\n<p>This method also is much faster than most of the above methods. It works for all cases except when the key actually has undefined value, or if the key starts with a number.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"8_Check_Multiple_Keys\"><\/span>8. Check Multiple Keys<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you want to check for the presence or absence or multiple keys, you can store them in an array, loop through the array, and in each iteration, use any of the above methods to individually check if the key is present in the object or not. Here is an example to check if keys 3 and 4 are present in the data object.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">keys=[3, 4];<br>for(i in keys){<br>  console.log(keys[i] in data);<br>}<\/pre>\n\n\n\n<p>Here is the output.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">true \/\/ for 3<br>true \/\/ for 4<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt several simple ways to easily check if a key exists or not in a JS object. You can use any of these methods but it is important to remember that in most cases, string or alphanumeric keys need to be mentioned within quotes whereas numeric keys may or may not be mentioned within quotes. Also, among them, accessing JS object as map or object (solutions #6 and #7), is the fastest way to check whether key exists or not. You can use any of these solutions as per your requirement.<\/p>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-insert-item-into-js-array-at-specific-index\/\">How to Insert Item In JS Array At Specific Index<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/what-does-strict-do-in-javascript\/\">What Does Strict Do in JavaScript<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/\">How to Check If Array Includes Value in JavaScript<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Often web developers need to check if keys exists in JavaScript object. Here are the different ways to do this.<\/p>\n","protected":false},"author":1,"featured_media":6722,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[295],"tags":[376],"class_list":["post-6691","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-key-exists"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Check if Key Exists in JavaScript Object - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Often web developers need to check if key exists in JavaScript object. Here are the different ways to do this.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Check if Key Exists in JavaScript Object - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Often web developers need to check if key exists in JavaScript object. Here are the different ways to do this.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2025-01-17T07:28:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-17T07:41:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/check-if-key-exists-in-javascript.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"300\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Check if Key Exists in JavaScript Object\",\"datePublished\":\"2025-01-17T07:28:10+00:00\",\"dateModified\":\"2025-01-17T07:41:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/\"},\"wordCount\":1319,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/check-if-key-exists-in-javascript.jpg?fit=300%2C200&ssl=1\",\"keywords\":[\"key exists\"],\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/\",\"url\":\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/\",\"name\":\"How to Check if Key Exists in JavaScript Object - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/check-if-key-exists-in-javascript.jpg?fit=300%2C200&ssl=1\",\"datePublished\":\"2025-01-17T07:28:10+00:00\",\"dateModified\":\"2025-01-17T07:41:43+00:00\",\"author\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Often web developers need to check if key exists in JavaScript object. Here are the different ways to do this.\",\"breadcrumb\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/check-if-key-exists-in-javascript.jpg?fit=300%2C200&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/check-if-key-exists-in-javascript.jpg?fit=300%2C200&ssl=1\",\"width\":300,\"height\":200,\"caption\":\"check if key exists in javascript\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/ubiq.co\/tech-blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Check if Key Exists in JavaScript Object\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#website\",\"url\":\"https:\/\/ubiq.co\/tech-blog\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/\"],\"url\":\"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Check if Key Exists in JavaScript Object - Ubiq BI","description":"Often web developers need to check if key exists in JavaScript object. Here are the different ways to do this.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/","og_locale":"en_US","og_type":"article","og_title":"How to Check if Key Exists in JavaScript Object - Ubiq BI","og_description":"Often web developers need to check if key exists in JavaScript object. Here are the different ways to do this.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2025-01-17T07:28:10+00:00","article_modified_time":"2025-01-17T07:41:43+00:00","og_image":[{"width":300,"height":200,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/check-if-key-exists-in-javascript.jpg","type":"image\/jpeg"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Check if Key Exists in JavaScript Object","datePublished":"2025-01-17T07:28:10+00:00","dateModified":"2025-01-17T07:41:43+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/"},"wordCount":1319,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/check-if-key-exists-in-javascript.jpg?fit=300%2C200&ssl=1","keywords":["key exists"],"articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/","name":"How to Check if Key Exists in JavaScript Object - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/check-if-key-exists-in-javascript.jpg?fit=300%2C200&ssl=1","datePublished":"2025-01-17T07:28:10+00:00","dateModified":"2025-01-17T07:41:43+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Often web developers need to check if key exists in JavaScript object. Here are the different ways to do this.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/check-if-key-exists-in-javascript.jpg?fit=300%2C200&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/check-if-key-exists-in-javascript.jpg?fit=300%2C200&ssl=1","width":300,"height":200,"caption":"check if key exists in javascript"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-key-exists-in-javascript-object\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Check if Key Exists in JavaScript Object"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/check-if-key-exists-in-javascript.jpg?fit=300%2C200&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1JV","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/6691","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=6691"}],"version-history":[{"count":45,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/6691\/revisions"}],"predecessor-version":[{"id":6740,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/6691\/revisions\/6740"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/6722"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=6691"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=6691"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=6691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}