{"id":7124,"date":"2025-02-14T07:09:18","date_gmt":"2025-02-14T07:09:18","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=7124"},"modified":"2025-02-14T07:09:20","modified_gmt":"2025-02-14T07:09:20","slug":"how-to-get-unique-values-in-javascript-array","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-get-unique-values-in-javascript-array\/","title":{"rendered":"How to Get Unique Values in JavaScript Array"},"content":{"rendered":"\n<p>Web developers commonly use JavaScript arrays to store different kinds of data. They offer tons of useful functions and capabilities. Often JavaScript developers need to remove duplicates and get unique values in JavaScript arrays. There are several simple ways to do this. In this article, we will learn how to get unique values in JavaScript array.<\/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-get-unique-values-in-javascript-array\/#Why_Remove_Duplicate_in_JavaScript_Array\" >Why Remove Duplicate in JavaScript Array<\/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-get-unique-values-in-javascript-array\/#How_to_Get_Unique_Values_in_JavaScript_Array\" >How to Get Unique Values in JavaScript Array<\/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-get-unique-values-in-javascript-array\/#1_Using_Spread_Operator_Set\" >1. Using Spread Operator &amp; Set<\/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-get-unique-values-in-javascript-array\/#2_Using_Filter_Method\" >2. Using Filter Method<\/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-get-unique-values-in-javascript-array\/#3_Using_Includes_Method\" >3. Using Includes Method<\/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-get-unique-values-in-javascript-array\/#4_Using_Underscore_library\" >4. Using Underscore library<\/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-get-unique-values-in-javascript-array\/#5_Using_Array_Prototype\" >5. Using Array 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-get-unique-values-in-javascript-array\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_Remove_Duplicate_in_JavaScript_Array\"><\/span>Why Remove Duplicate in JavaScript Array<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Sometimes, you may receive data with duplicates in them. You may need to clean it up before you can analyze it further. Therefore, you will need to remove duplicates and get unique values in JavaScript array.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Get_Unique_Values_in_JavaScript_Array\"><\/span>How to Get Unique Values in JavaScript Array<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are some of the most popular ways to remove duplicates from JavaScript arrays.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_Spread_Operator_Set\"><\/span>1. Using Spread Operator &amp; Set<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this solution, we first convert the array into a set. By definition, a set can have only unique items. Therefore this operation automatically drops all duplicate items. Then we convert this set into an array, using spread operator &#8216;&#8230;&#8217; and array constructor.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a = [1, 2, 2, 3];<br>b = new Set(a);<br>a = [...b];<br>console.log(a); \/\/ output is [1, 2, 3]<\/pre>\n\n\n\n<p>In the above code, if do not prefix the set with spread operator, then it will not unpack the items of the set before storing them into an array. Here is what happens if you do not use spread operator above.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a = [1, 2, 2, 3];<br>b = new Set(a);<br>a = [b];<br>console.log(a); \/\/ output is [ Set(3) { 1, 2, 3 } ]<\/pre>\n\n\n\n<p>You can also use Array() constructor to create array from set. You will get the same output.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a = [1, 2, 2, 3];<br>b = new Set(a);<br>a = Array(...b);<br>console.log(a); \/\/ output is [1, 2, 3]<\/pre>\n\n\n\n<p>This is the most convenient and recommended way to get unique values from JavaScript array.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_Filter_Method\"><\/span>2. Using Filter Method<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can also use filter() method to remove duplicates from JavaScript array. Filter method allows you to create a new array from another array using items that satisfy one or more conditions specified in filter function.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a = [1, 2, 2, 3];<br>a = a.filter((x, i, a) => a.indexOf(x) == i)<br>console.log(a); \/\/ output is [1, 2, 3]<\/pre>\n\n\n\n<p>In the above code, we define a filter function, which loops through the array and checks if its index is equal to the index returned by indexOf() function. indexOf() function returns the index of first occurrence of an item in an array. So if an item is a duplicate then its index will not be equal to the result returned by indexOf() function, and it will not be returned by filter() method. Therefore, the result of filter method will contain only the first occurrence of each unique item in the array.<\/p>\n\n\n\n<p>If you find the above code to be complicated, you can simplify it by separately defining a function check_index() that returns true if the index of said item is equal to its first occurrence, else it returns false.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">function check_index(value, index, array) {<br>  return array.indexOf(value) === index;<br>}<br><br>a = [1, 2, 2, 3];<br>a = a.filter(check_index)<br>console.log(a); \/\/ output is [1, 2, 3]<\/pre>\n\n\n\n<p>The previous method removes all duplicates from the array. There is no way to customize it. But if you want to selectively remove only certain duplicates then you can modify your check_index function to exclude those duplicates.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_Includes_Method\"><\/span>3. Using Includes Method<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The includes() method checks whether a given item is present in an array or not. If it is present, then it returns true, else it returns false. We can use it to get unique items from JS array. In this approach, we create an empty array to store the array items without duplicates. We loop through the original array and in each iteration, we check if the given item is present in the new array or not. For this, we use includes() function. If it is not present, then we add it to the new array.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a = [1, 2, 2, 3];<br>a1 = [];<br>for (let i = 0; i &lt; a.length; i++) {<br>    <br>    \/\/ Check if item is present in new array<br>    if (!a1.includes(a[i])) {<br>    <br>        \/\/ If not then push item to new array<br>        a1.push(a[i]);<br>    }<br>}<br>console.log(a1); \/\/ output is [1, 2, 3]<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Using_Underscore_library\"><\/span>4. Using Underscore library<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Underscore is a popular JavaScript library that offers many functions for data manipulation. If you happen to use it in your website or application, then you can directly call its uniq() function to get unique values in array.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;script src=\"http:\/\/underscorejs.org\/underscore-min.js\">&lt;\/script><br>a = [1, 2, 2, 3];<br>console.log(_.uniq(a)); \/\/ output is [1, 2, 3]<br><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Using_Array_Prototype\"><\/span>5. Using Array Prototype<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you commonly need to remove duplicates from array, then you can create a Prototype function that can be called on all JS arrays.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Array.prototype.unique = function() {<br>    return [...new Set(this)];<br>}<br>a = [1, 2, 2, 3];<br><br>console.log(a.unique());<\/pre>\n\n\n\n<p>In the above function we simply call array constructor and set function on <em>this<\/em> that is the present Array under consideration. Once you define this in your JavaScript file, you can call it directly on any array on your web page..<\/p>\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 remove duplicates from JavaScript array. Using spread operator and set function is the easiest way to get unique items in JavaScript array. If you want to selectively remove only some duplicates from your array, then you can use filter() function where you specify the exclusion of certain duplicates. If you use third-party libraries like underscore, then you can use their built-in functions to remove duplicates. We have also learnt how to create prototype function for an array so that it can be directly called from every array. You can use any of these methods depending on 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-copy-array-in-javascript\/\">How to Copy Array in JavaScript<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-empty-array-in-javascript\/\">How to Empty Array in JavaScript<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-javascript-objects\/\">How to Merge Two JavaScript Objects<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Often web developers need to remove duplicates from JavaScript array. Here are different ways to get unique values in JavaScript arrays.<\/p>\n","protected":false},"author":1,"featured_media":7144,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[295],"tags":[389],"class_list":["post-7124","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-remove-duplicate"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Get Unique Values in JavaScript Array - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Often web developers need to remove duplicates from JavaScript array. Here are different ways to get unique values in JavaScript array.\" \/>\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-get-unique-values-in-javascript-array\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Get Unique Values in JavaScript Array - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Often web developers need to remove duplicates from JavaScript array. Here are different ways to get unique values in JavaScript array.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-unique-values-in-javascript-array\/\" \/>\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-02-14T07:09:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-14T07:09:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/remove-duplicate-javascript-array.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"288\" \/>\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=\"4 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-get-unique-values-in-javascript-array\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-unique-values-in-javascript-array\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Get Unique Values in JavaScript Array\",\"datePublished\":\"2025-02-14T07:09:18+00:00\",\"dateModified\":\"2025-02-14T07:09:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-unique-values-in-javascript-array\\\/\"},\"wordCount\":795,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-unique-values-in-javascript-array\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/remove-duplicate-javascript-array.jpg?fit=288%2C192&ssl=1\",\"keywords\":[\"remove duplicate\"],\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-unique-values-in-javascript-array\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-unique-values-in-javascript-array\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-unique-values-in-javascript-array\\\/\",\"name\":\"How to Get Unique Values in JavaScript Array - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-unique-values-in-javascript-array\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-unique-values-in-javascript-array\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/remove-duplicate-javascript-array.jpg?fit=288%2C192&ssl=1\",\"datePublished\":\"2025-02-14T07:09:18+00:00\",\"dateModified\":\"2025-02-14T07:09:20+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Often web developers need to remove duplicates from JavaScript array. Here are different ways to get unique values in JavaScript array.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-unique-values-in-javascript-array\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-unique-values-in-javascript-array\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-unique-values-in-javascript-array\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/remove-duplicate-javascript-array.jpg?fit=288%2C192&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/remove-duplicate-javascript-array.jpg?fit=288%2C192&ssl=1\",\"width\":288,\"height\":192,\"caption\":\"remove duplicate from javascript array\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-unique-values-in-javascript-array\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Get Unique Values in JavaScript Array\"}]},{\"@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 Get Unique Values in JavaScript Array - Ubiq BI","description":"Often web developers need to remove duplicates from JavaScript array. Here are different ways to get unique values in JavaScript array.","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-get-unique-values-in-javascript-array\/","og_locale":"en_US","og_type":"article","og_title":"How to Get Unique Values in JavaScript Array - Ubiq BI","og_description":"Often web developers need to remove duplicates from JavaScript array. Here are different ways to get unique values in JavaScript array.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-get-unique-values-in-javascript-array\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2025-02-14T07:09:18+00:00","article_modified_time":"2025-02-14T07:09:20+00:00","og_image":[{"width":288,"height":192,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/remove-duplicate-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":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-unique-values-in-javascript-array\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-unique-values-in-javascript-array\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Get Unique Values in JavaScript Array","datePublished":"2025-02-14T07:09:18+00:00","dateModified":"2025-02-14T07:09:20+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-unique-values-in-javascript-array\/"},"wordCount":795,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-unique-values-in-javascript-array\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/remove-duplicate-javascript-array.jpg?fit=288%2C192&ssl=1","keywords":["remove duplicate"],"articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-get-unique-values-in-javascript-array\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-unique-values-in-javascript-array\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-get-unique-values-in-javascript-array\/","name":"How to Get Unique Values in JavaScript Array - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-unique-values-in-javascript-array\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-unique-values-in-javascript-array\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/remove-duplicate-javascript-array.jpg?fit=288%2C192&ssl=1","datePublished":"2025-02-14T07:09:18+00:00","dateModified":"2025-02-14T07:09:20+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Often web developers need to remove duplicates from JavaScript array. Here are different ways to get unique values in JavaScript array.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-unique-values-in-javascript-array\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-get-unique-values-in-javascript-array\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-unique-values-in-javascript-array\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/remove-duplicate-javascript-array.jpg?fit=288%2C192&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/remove-duplicate-javascript-array.jpg?fit=288%2C192&ssl=1","width":288,"height":192,"caption":"remove duplicate from javascript array"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-unique-values-in-javascript-array\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Get Unique Values in JavaScript Array"}]},{"@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\/02\/remove-duplicate-javascript-array.jpg?fit=288%2C192&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1QU","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7124","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=7124"}],"version-history":[{"count":19,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7124\/revisions"}],"predecessor-version":[{"id":7143,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7124\/revisions\/7143"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/7144"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=7124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=7124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=7124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}