{"id":37,"date":"2019-04-23T16:02:22","date_gmt":"2019-04-23T16:02:22","guid":{"rendered":"http:\/\/santosh-shah.com\/blog\/remove-duplicate-array-via-vanilla-javascript\/"},"modified":"2019-04-23T16:02:22","modified_gmt":"2019-04-23T16:02:22","slug":"remove-duplicate-array-via-vanilla-javascript","status":"publish","type":"post","link":"https:\/\/santosh-shah.com\/blog\/remove-duplicate-array-via-vanilla-javascript\/","title":{"rendered":"Remove duplicate array via vanilla JavaScript"},"content":{"rendered":"<p>In this, another small tutorial I am going to show you how you simply remove the duplicate array from any array given. This is a very simple trick, so you don\u2019t require any other plugin or framework. I am going to show you how to remove duplicate array via vanilla JavaScript only.<\/p>\n<h2>Remove duplicate array via vanilla JavaScript easy<\/h2>\n<pre><code>var duplicateArray = [1,1,1,5,6,3,2,8,9,5,2,2,4,4];\nvar cleanArray = [];<\/code><\/pre>\n<p>In the above array, we have many duplicate numbers we see. Now in order to remove duplicate value from the array, we run a loop. Also, we initialize a new blank array, where we are going to push all the unique items removing duplicate array.<\/p>\n<pre><code>for(var i=0; i&lt;duplicateArray.length; i++){ \n    if(cleanArray.indexOf(duplicateArray[i]) === -1){ \n         cleanArray.push(duplicateArray[i])\n    } \n}<\/code><\/pre>\n<p>The first line <code> for(var i=0; i, simply states that we are inititating <code>for<\/code> loop for duplicateArray.<\/code><\/p>\n<p>The second line <code> if(cleanArray.indexOf(duplicateArray[i]) === -1){  <\/code>, we are checking if the loop item `duplicateArray[i]` doesn&#8217;t exist in our new blank array so called <code>cleanArray[]<\/code>. So if the loop item is not present in the <code>cleanArray[]<\/code> then we push the loop inside the <code>cleanArray[]<\/code>. The -1 return when the indexOf() method doesn&#8217;t find the position of loop value.<\/p>\n<p>In the next third line we simply push the new item filter from the second line to our <code>cleanArray[]<\/code><\/p>\n<p>Hope it helps anyone.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this, another small tutorial I am going to show you how you simply remove the duplicate array from any array given. This is a very simple trick, so you don\u2019t require any other plugin or framework. I am going to show you how to remove duplicate array via vanilla JavaScript only. Remove duplicate array [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-37","post","type-post","status-publish","format-standard","hentry","category-javascript"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Remove duplicate array via vanilla JavaScript - Santosh Kumar Shah<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/santosh-shah.com\/blog\/remove-duplicate-array-via-vanilla-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Remove duplicate array via vanilla JavaScript - Santosh Kumar Shah\" \/>\n<meta property=\"og:description\" content=\"In this, another small tutorial I am going to show you how you simply remove the duplicate array from any array given. This is a very simple trick, so you don\u2019t require any other plugin or framework. I am going to show you how to remove duplicate array via vanilla JavaScript only. Remove duplicate array [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/santosh-shah.com\/blog\/remove-duplicate-array-via-vanilla-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"Santosh Kumar Shah\" \/>\n<meta property=\"article:published_time\" content=\"2019-04-23T16:02:22+00:00\" \/>\n<meta name=\"author\" content=\"Santosh Kumar Shah\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Santosh Kumar Shah\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/santosh-shah.com\/blog\/remove-duplicate-array-via-vanilla-javascript\/\",\"url\":\"https:\/\/santosh-shah.com\/blog\/remove-duplicate-array-via-vanilla-javascript\/\",\"name\":\"Remove duplicate array via vanilla JavaScript - Santosh Kumar Shah\",\"isPartOf\":{\"@id\":\"https:\/\/santosh-shah.com\/blog\/#website\"},\"datePublished\":\"2019-04-23T16:02:22+00:00\",\"author\":{\"@id\":\"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/b17cb45bdd5f518e74a08ad2c6c4b39f\"},\"breadcrumb\":{\"@id\":\"https:\/\/santosh-shah.com\/blog\/remove-duplicate-array-via-vanilla-javascript\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/santosh-shah.com\/blog\/remove-duplicate-array-via-vanilla-javascript\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/santosh-shah.com\/blog\/remove-duplicate-array-via-vanilla-javascript\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/santosh-shah.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Remove duplicate array via vanilla JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/santosh-shah.com\/blog\/#website\",\"url\":\"https:\/\/santosh-shah.com\/blog\/\",\"name\":\"Santosh Kumar Shah\",\"description\":\"JavaScript Developer\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/santosh-shah.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/b17cb45bdd5f518e74a08ad2c6c4b39f\",\"name\":\"Santosh Kumar Shah\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cf46c57219d897547f3204b6b302169b3302b17507ccc902946b622a78d0b98b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cf46c57219d897547f3204b6b302169b3302b17507ccc902946b622a78d0b98b?s=96&d=mm&r=g\",\"caption\":\"Santosh Kumar Shah\"},\"description\":\"I am JavaScript developer.\",\"sameAs\":[\"https:\/\/santosh-shah.com\/blog\"],\"url\":\"https:\/\/santosh-shah.com\/blog\/author\/sks7yu\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Remove duplicate array via vanilla JavaScript - Santosh Kumar Shah","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:\/\/santosh-shah.com\/blog\/remove-duplicate-array-via-vanilla-javascript\/","og_locale":"en_US","og_type":"article","og_title":"Remove duplicate array via vanilla JavaScript - Santosh Kumar Shah","og_description":"In this, another small tutorial I am going to show you how you simply remove the duplicate array from any array given. This is a very simple trick, so you don\u2019t require any other plugin or framework. I am going to show you how to remove duplicate array via vanilla JavaScript only. Remove duplicate array [&hellip;]","og_url":"https:\/\/santosh-shah.com\/blog\/remove-duplicate-array-via-vanilla-javascript\/","og_site_name":"Santosh Kumar Shah","article_published_time":"2019-04-23T16:02:22+00:00","author":"Santosh Kumar Shah","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Santosh Kumar Shah","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/santosh-shah.com\/blog\/remove-duplicate-array-via-vanilla-javascript\/","url":"https:\/\/santosh-shah.com\/blog\/remove-duplicate-array-via-vanilla-javascript\/","name":"Remove duplicate array via vanilla JavaScript - Santosh Kumar Shah","isPartOf":{"@id":"https:\/\/santosh-shah.com\/blog\/#website"},"datePublished":"2019-04-23T16:02:22+00:00","author":{"@id":"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/b17cb45bdd5f518e74a08ad2c6c4b39f"},"breadcrumb":{"@id":"https:\/\/santosh-shah.com\/blog\/remove-duplicate-array-via-vanilla-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/santosh-shah.com\/blog\/remove-duplicate-array-via-vanilla-javascript\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/santosh-shah.com\/blog\/remove-duplicate-array-via-vanilla-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/santosh-shah.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Remove duplicate array via vanilla JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/santosh-shah.com\/blog\/#website","url":"https:\/\/santosh-shah.com\/blog\/","name":"Santosh Kumar Shah","description":"JavaScript Developer","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/santosh-shah.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/b17cb45bdd5f518e74a08ad2c6c4b39f","name":"Santosh Kumar Shah","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cf46c57219d897547f3204b6b302169b3302b17507ccc902946b622a78d0b98b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cf46c57219d897547f3204b6b302169b3302b17507ccc902946b622a78d0b98b?s=96&d=mm&r=g","caption":"Santosh Kumar Shah"},"description":"I am JavaScript developer.","sameAs":["https:\/\/santosh-shah.com\/blog"],"url":"https:\/\/santosh-shah.com\/blog\/author\/sks7yu\/"}]}},"_links":{"self":[{"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/posts\/37","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/comments?post=37"}],"version-history":[{"count":0,"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/posts\/37\/revisions"}],"wp:attachment":[{"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/media?parent=37"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/categories?post=37"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/tags?post=37"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}