# Removing Duplicate Arrays from an Array of Arrays

**URL:** <https://forum.kirupa.com/t/removing-duplicate-arrays-from-an-array-of-arrays/641147>\
**Category:** programming\
**Created:** [November 21, 2019, 2:26pm UTC](https://forum.kirupa.com/t/removing-duplicate-arrays-from-an-array-of-arrays/641147 "2019-11-21T14:26:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [November 21, 2019, 2:26pm UTC](https://forum.kirupa.com/t/removing-duplicate-arrays-from-an-array-of-arrays/641147/1 "2019-11-21T14:26:59Z")

</div>

In the [Useful Array Tricks](https://www.kirupa.com/html5/array_tricks.htm) article, one of the tricks described how to ensure the contents of our array are unique and no duplicate items exist. The technique described really only worked when the array items in question were primitives like text or numbers. In this article, we will go one step further and look at another common case. What if the array items with potential duplicates were themselves arrays? How will we both identify the duplicate arrays and also remove those duplicates to ensure we have an array made up only of unique arrays? In this article, we’ll find out how!

* * *
This is a companion discussion topic for the original entry at [https://www.kirupa.com/javascript/removing\_duplicate\_arrays\_from\_array.htm](https://www.kirupa.com/javascript/removing_duplicate_arrays_from_array.htm)

---

<div class="post-metadata">

**Author:** ![REB\_412](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/reb_412/32/9233_2.png) [@REB\_412](https://forum.kirupa.com/u/REB_412)\
**Post date:** [November 24, 2019, 12:30am UTC](https://forum.kirupa.com/t/removing-duplicate-arrays-from-an-array-of-arrays/641147/2 "2019-11-24T00:30:02Z")

</div>

Really enjoyed this article and didn’t even think about your approach when I saw your initial question. Glad you published the article and pointed out these additional methods.

---

<div class="post-metadata">

**Author:** ![reyimar](https://avatars.discourse-cdn.com/v4/letter/r/aca169/32.png) [@reyimar](https://forum.kirupa.com/u/reyimar)\
**Post date:** [January 22, 2020, 2:40pm UTC](https://forum.kirupa.com/t/removing-duplicate-arrays-from-an-array-of-arrays/641147/3 "2020-01-22T14:40:04Z")

</div>

that is very useful

---

<div class="post-metadata">

**Author:** ![swasak](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/swasak/32/12653_2.png) [@swasak](https://forum.kirupa.com/u/swasak)\
**Post date:** [October 14, 2020, 11:02pm UTC](https://forum.kirupa.com/t/removing-duplicate-arrays-from-an-array-of-arrays/641147/4 "2020-10-14T23:02:21Z")

</div>

This is so well explained .Thank you for the detailed explanation.  
I have a list of stores with in an array.Each item in an array is an array with the store name and distance.I want to filter out the items that are closer to me.

Input: [[“Chipotle” , 0.2],  
["Starbucks: , 0.3],  
[“Safeway”, 0.4],  
[“Safeway”, 0.2],  
[“Starbucks”, 0.4],  
].

OUTPUT should be: [[“Chipotle” , 0.2],  
["Starbucks: , 0.3],  
[“Safeway”, 0.2],  
].  
Any idea?

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [October 16, 2020, 12:46am UTC](https://forum.kirupa.com/t/removing-duplicate-arrays-from-an-array-of-arrays/641147/5 "2020-10-16T00:46:19Z")

</div>

Hey Swasak! I will try to post a more detailed response, but the way to approach this is to:

1. Sort by distance: [https://www.kirupa.com/html5/array\_tricks.htm#array\_sorting](https://www.kirupa.com/html5/array_tricks.htm#array_sorting)
2. Filter out the further away values by whatever criteria you come up with

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [October 16, 2020, 10:01pm UTC](https://forum.kirupa.com/t/removing-duplicate-arrays-from-an-array-of-arrays/641147/6 "2020-10-16T22:01:01Z")

</div>

From a performance point of view, filtering first and then sorting may be better! Not sure why I randomly thought of that right now 😀

---

<div class="post-metadata">

**Author:** ![Jerry\_Seigle](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jerry_seigle/32/12947_2.png) [@Jerry\_Seigle](https://forum.kirupa.com/u/Jerry_Seigle)\
**Post date:** [January 9, 2021, 6:53pm UTC](https://forum.kirupa.com/t/removing-duplicate-arrays-from-an-array-of-arrays/641147/7 "2021-01-09T18:53:48Z")

</div>

Is there a way to do the opposite? Remove from parent and keep the duplicate in child array.

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [January 11, 2021, 6:48pm UTC](https://forum.kirupa.com/t/removing-duplicate-arrays-from-an-array-of-arrays/641147/8 "2021-01-11T18:48:45Z")

</div>

@Jerry_Seigle. Do you mean something like this?

```auto
let original = [1,2,2,3,3,3] 
let removed = removeDuplicates(original)
// original = [1,2,3]
// removed = [2,3,3]

```
