Skip to main content

Posts

Showing posts from November, 2019

Remove Duplicates from JS array - [Solved]

Here we are gonna see how to remove duplicates from JS array in either of the below format, Duplicates in an Array (or) Duplicates in an Array of Objects Let's go through each in detail. Duplicates in an Array Assume you have duplicates in a list of the country array, var countries=["China","India","United States","Indonesia", "India","Pakistan" ]; As you can see in the above array, country India is repeating twice from the list. In order to get an accurate unique country list, you can use any of the following methods. jQuery Hashtables Sort jQuery See the Pen Remove Duplicates in an array using jQuery by Prime Study Hub ( @PrimeStudyHub ) on CodePen . This method loops through your original array and finds the duplicate items and removes them and updates the non-duplicate items into the new array. Hashtable See the Pen Remove Duplicates in an array using Hashtable by Prime Study Hub ( @Prim