{"id":6461,"date":"2025-01-07T06:24:06","date_gmt":"2025-01-07T06:24:06","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=6461"},"modified":"2025-01-08T06:51:36","modified_gmt":"2025-01-08T06:51:36","slug":"how-to-check-if-array-includes-value-in-javascript","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/","title":{"rendered":"How to Check if Array Includes Value in JavaScript"},"content":{"rendered":"\n<p>Web developers commonly use JavaScript arrays to store data. They are versatile data structures that allow you to store different types of data, and support a wide range of built-in functions. If your code depends on a specific value of an array element, and if that value is not present in your array, then your code will not work as expected. Therefore, web developers often check if JS arrays include specific value in JavaScript, to avoid such use cases. In this article, we will learn several different ways to check if array includes value using plain JavaScript.<\/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-array-includes-value-in-javascript\/#How_to_Check_if_Array_Includes_Value_in_JavaScript\" >How to Check if Array Includes Value in JavaScript<\/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-array-includes-value-in-javascript\/#1_Using_arrayincludes\" >1. Using array.includes()<\/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-array-includes-value-in-javascript\/#2_Using_indexOf\" >2. Using indexOf()<\/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-array-includes-value-in-javascript\/#3_Using_find_function\" >3. Using find() function<\/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-array-includes-value-in-javascript\/#4_Using_filter_function\" >4. Using filter() function<\/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-array-includes-value-in-javascript\/#5_Using_some_function\" >5. Using some() function<\/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-array-includes-value-in-javascript\/#6_Using_function_prototype\" >6. Using function prototype<\/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-array-includes-value-in-javascript\/#7_Using_for_loop\" >7. Using for loop<\/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-array-includes-value-in-javascript\/#8_Using_jQuery\" >8. Using jQuery<\/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-array-includes-value-in-javascript\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Check_if_Array_Includes_Value_in_JavaScript\"><\/span>How to Check if Array Includes Value in JavaScript<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>There are plenty of ways to check if array includes value. Let us look at some of them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_arrayincludes\"><\/span>1. Using array.includes()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The includes() method returns true if an element exists in an array, else it returns false. It is available by default in every JS array. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">array.includes(element)<\/pre>\n\n\n\n<p>Let us say you have the following array.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a = [1, 2, 3, 4, 5]<\/pre>\n\n\n\n<p>Here is the command to find if element 3 exists in the array.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log(a.includes(3)) \/\/ returns true<\/pre>\n\n\n\n<p>Here is the command to check if element 10 exists in the array.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log(a.includes(10)) \/\/ returns false<\/pre>\n\n\n\n<p>Please note, this is one of the fastest and most commonly used methods to look for an element in an array. It works on primitive data types as well as if your array contains JS objects and you need to check if an object is present in the array. Here is an example to illustrate it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a = [{b:2},{c:3},{d:4}];<br>console.log(a.includes(a[1])) \/\/ returns true<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_indexOf\"><\/span>2. Using indexOf()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>IndexOf() function returns the index of first occurrence of an item in an array. If the item is not present in the array, then it returns -1. So we can use this function to check if an item exists in an array. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">array.indexOf(element)<\/pre>\n\n\n\n<p>Here is an example to check if an array includes an element, using indexOf() function.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">data = [1, 2, 3, 4, 5];<br>item = 3;<br>index = data.indexOf(item);<br><br>if( index &gt;= 0 ){<br>  console.log('item exists')<br>}else{<br>  console.log('item does not exist')<br>}<\/pre>\n\n\n\n<p>This is also a very fast solution like using includes() function.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_find_function\"><\/span>3. Using find() function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>find() function allows you to test a condition against every element of an array and returns the first item that satisfies the condition. If there is no element that satisfies the condition, it returns undefined. Here is an example to illustrate it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a = [1, 2, 3, 4, 5];<br>n1 = 3;<br>n2 = 6;<br><br>console.log(a.find(element =&gt; element === n1))  \/\/returns 3<br>console.log(a.find(element =&gt; element === n2))  \/\/ returns undefined<\/pre>\n\n\n\n<p>In the above code, we define a test condition that checks each element to see if it is equal to n1. The find() function loops through the array, and in each iteration, checks if the present item <em>element<\/em> is equal to n1. We do the same thing with n2. In first case, it returns 3 and in the second case, it returns undefined.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Using_filter_function\"><\/span>4. Using filter() function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In JavaScript, filter() function iterates through a given array, tests each of its elements for a given condition, and creates a new array with all those elements that satisfy the condition. If no element satisfies the condition, it returns an empty array. So we can use the condition to check if our desired element is present in array.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a = [1, 2, 3, 4, 5];<br>n=6<br>f_arr= a.filter(element =&gt; element === n);<\/pre>\n\n\n\n<p>In the above code, we define an array a and the element n to be searched for. In filter() function, we check if in each iteration, if the present element is equal to the desired element n to be searched. All matching elements are stored in f_arr array.<\/p>\n\n\n\n<p>In our case, since the element 6 is not present in original array, we will get an empty array. You can check if the result of filter() function is empty or not to determine if the element is present in the original array.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">if(f_arr.length&gt;0){<br>  console.log('element is present');<br>}else{<br>  console.log('element is not present');<br>}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Using_some_function\"><\/span>5. Using some() function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>All the above solutions work with primitive data types such as numbers and texts. For example, it works with an array or numbers or strings. What if you have an array of JS objects. If you want to check if a specific item is present in an array or not, then you can use some() function.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">data = [ {b: '1'}, {b: '2'}, {b: '3'} ]<br><br>data.some(data =&gt; data.b === '3')  \/\/ returns true<br>data.some(data =&gt; data.b === '4')  \/\/ returns false<\/pre>\n\n\n\n<p>In the first case above, some() function iterates through each item of the data array. In each iteration, it checks if the b key&#8217;s value is equal to 3. Since one of the elements matches this condition, it returns true. In second case, since there is no match, it returns false.<\/p>\n\n\n\n<p>This approach is slower that using includes() and indexOf() functions mentioned above. But it is very useful in doing complicated lookups such as searching for an item in an array of JS objects.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6_Using_function_prototype\"><\/span>6. Using function prototype<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Prototype functions are user-defined functions that can be invoked on the data type for which they are defined. You can also define a function prototype to easily re-use it everywhere across your site. We will define a prototype function to check if an array contains an item.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Array.prototype.contains = function(obj) {<br>    var i = this.length;<br>    while (i--) {<br>        if (this[i] === obj) {<br>            return true;<br>        }<br>    }<br>    return false;<br>}<\/pre>\n\n\n\n<p>In the above function contains(), we accept an input argument obj that we need to check if it is present in the array. We calculate the length of the array and using a while loop, iterate through each item of the array. In each iteration, we check if the array item is equal to the desired item to be searched. If it is found,  the function returns true, else it returns false. Here is how you can call it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log([1, 2, 3].contains(2)); \/\/ output is true<br>console.log([1, 2, 3].contains(4)); \/\/ output is false<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"7_Using_for_loop\"><\/span>7. Using for loop<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This is the most basic method to check if an array contains an item. It is slower than other methods but it is useful for very old web browsers that may not support other solutions. In this case, we simply loop through the array and in each iteration, check if the present item matches the desired element to be searched.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a = [1, 2, 3, 4, 5];<br>n = 3;<br>for (let i = 0; i &lt; a.length; i++){<br>   if (a[i] == n)<br>   return n + ' is present';<br> }<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"8_Using_jQuery\"><\/span>8. Using jQuery<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>jQuery is a popular JavaScript library that makes it very easy to work with different types of data as well as page elements. It provides inArray() function that checks if an array contains a specific value.<\/p>\n\n\n\n<p>Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$.inArray(value, array, [fromIndex])<\/pre>\n\n\n\n<p>In the above function, the first argument is the value to be searched, the second argument is the array. The third argument is optional. It stands for the array index from where to begin the search. This is useful if you already have a good idea where the element is located in the array.<\/p>\n\n\n\n<p>Here is an example to check if item 3 is present in array [1, 2, 3, 4, 5]<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$.inArray(3, [1, 2, 3, 4, 5])<\/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 different ways to easily check if an element is present in an array or not. You can use any of these methods to check if array includes value as per your requirement. Among them, using includes() and indexOf() functions will give the fastest results. They work well on large arrays also. But they mainly work if your array items are primitive data types such as numbers and strings. They also work if array items are JS objects and also the item you are looking for is also an object. But if your array contains JS objects and you need to check if an item is present in any of the values in any of the object, then you can use some() to quickly check if any of the objects contains a specific value.<\/p>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-move-element-into-other-element-in-jquery\/\">How to Move Element Into Other Element in jQuery<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-remove-duplicate-values-from-js-array\/\">How to Remove Duplicate Values from JS Array<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/difference-between-let-and-var-in-javascript\/\">Difference Between Let and Var in JavaScript<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Often web developers need to check if JS array contains specific value. Here are different ways to check if array includes value in JavaScript.<\/p>\n","protected":false},"author":1,"featured_media":6503,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[295],"tags":[371],"class_list":["post-6461","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-array-includes"],"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 Array Includes Value in JavaScript - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Web developers need to check if JS array contains specific value. Here are different ways to check if array includes value in JavaScript.\" \/>\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-array-includes-value-in-javascript\/\" \/>\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 Array Includes Value in JavaScript - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Web developers need to check if JS array contains specific value. Here are different ways to check if array includes value in JavaScript.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/\" \/>\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-07T06:24:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-08T06:51:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/check-item-in-javascript-array.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"256\" \/>\n\t<meta property=\"og:image:height\" content=\"192\" \/>\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-array-includes-value-in-javascript\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Check if Array Includes Value in JavaScript\",\"datePublished\":\"2025-01-07T06:24:06+00:00\",\"dateModified\":\"2025-01-08T06:51:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/\"},\"wordCount\":1195,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/check-item-in-javascript-array.jpg?fit=256%2C192&ssl=1\",\"keywords\":[\"array includes\"],\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/\",\"url\":\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/\",\"name\":\"How to Check if Array Includes Value in JavaScript - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/check-item-in-javascript-array.jpg?fit=256%2C192&ssl=1\",\"datePublished\":\"2025-01-07T06:24:06+00:00\",\"dateModified\":\"2025-01-08T06:51:36+00:00\",\"author\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Web developers need to check if JS array contains specific value. Here are different ways to check if array includes value in JavaScript.\",\"breadcrumb\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/check-item-in-javascript-array.jpg?fit=256%2C192&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/check-item-in-javascript-array.jpg?fit=256%2C192&ssl=1\",\"width\":256,\"height\":192,\"caption\":\"check if array includes value\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/ubiq.co\/tech-blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Check if Array Includes Value in JavaScript\"}]},{\"@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 Array Includes Value in JavaScript - Ubiq BI","description":"Web developers need to check if JS array contains specific value. Here are different ways to check if array includes value in JavaScript.","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-array-includes-value-in-javascript\/","og_locale":"en_US","og_type":"article","og_title":"How to Check if Array Includes Value in JavaScript - Ubiq BI","og_description":"Web developers need to check if JS array contains specific value. Here are different ways to check if array includes value in JavaScript.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2025-01-07T06:24:06+00:00","article_modified_time":"2025-01-08T06:51:36+00:00","og_image":[{"width":256,"height":192,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/check-item-in-javascript-array.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-array-includes-value-in-javascript\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Check if Array Includes Value in JavaScript","datePublished":"2025-01-07T06:24:06+00:00","dateModified":"2025-01-08T06:51:36+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/"},"wordCount":1195,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/check-item-in-javascript-array.jpg?fit=256%2C192&ssl=1","keywords":["array includes"],"articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/","name":"How to Check if Array Includes Value in JavaScript - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/check-item-in-javascript-array.jpg?fit=256%2C192&ssl=1","datePublished":"2025-01-07T06:24:06+00:00","dateModified":"2025-01-08T06:51:36+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Web developers need to check if JS array contains specific value. Here are different ways to check if array includes value in JavaScript.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/check-item-in-javascript-array.jpg?fit=256%2C192&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/check-item-in-javascript-array.jpg?fit=256%2C192&ssl=1","width":256,"height":192,"caption":"check if array includes value"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-array-includes-value-in-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Check if Array Includes Value in JavaScript"}]},{"@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-item-in-javascript-array.jpg?fit=256%2C192&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1Gd","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/6461","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=6461"}],"version-history":[{"count":47,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/6461\/revisions"}],"predecessor-version":[{"id":6553,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/6461\/revisions\/6553"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/6503"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=6461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=6461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=6461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}