---
title: "How to remove duplicate entries in array?"  
description: "How to remove duplicate entries in array?"  
author: "David Miller"  
published: 2014-11-24  
updated: 2014-11-25  
canonical: https://www.mindstick.com/forum/12686/how-to-remove-duplicate-entries-in-array  
category: "javascript"  
tags: ["jquery", "array"]  
reading_time: 2 minutes  

---

# How to remove duplicate entries in array?

I have an [array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net) of [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) returned from my server. From this array I need to get an array of [Topics](https://yourviews.mindstick.com/story/2269/here-are-the-important-topics-in-the-history-and-culture-of-india-for-the-upsc-exam) and an array of SubTopics:

var data =

[

{"topicId":1,"subTopicId":1,"topicName":"J","subTopicName":" Ar"},

{"topicId":1,"subTopicId":2,"topicName":"J","subTopicName":" Us"},

{"topicId":1,"subTopicId":3,"topicName":"J","subTopicName":" Ut"},

{"topicId":2,"subTopicId":4,"topicName":"L","subTopicName":" Ov"},

{"topicId":2,"subTopicId":5,"topicName":"L","subTopicName":" El"},

{"topicId":2,"subTopicId":6,"topicName":"L","subTopicName":" In"},

{"topicId":2,"subTopicId":7,"topicName":"L","subTopicName":" Pr"},

{"topicId":2,"subTopicId":8,"topicName":"L","subTopicName":" Va"},

{"topicId":2,"subTopicId":9,"topicName":"L","subTopicName":" Pa"}

]

I have [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) that I use to reformat this data and just give me [topic](https://answers.mindstick.com/blog/313/how-to-generate-content-on-a-topic-using-ml-dot-net) information:

var topics = data.map([function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) (t) {

return {

id: t.topicId, name: t.topicName

};

});

But this gives me **three** entries for topicId 1 and **six** entries for topidId 2.

How I can [filter](https://www.mindstick.com/forum/1176/filter-in-a-xml-file-in-c-sharp) out [duplicate](https://www.mindstick.com/forum/160911/sql-query-to-find-duplicate-records-in-a-table-in-sql-server) entries so I can for example the above would just give me a topic array of two entries. One for each topicId

Please no jQuery, lodash or other [framework](https://www.mindstick.com/forum/34615/software-framework-vs-library) [solutions](https://www.mindstick.com/articles/12807/product-searching-issues-and-solutions-for-ecommerce-store-advanced-search-autocomplete-suggest) as I didn't include these in the tags. thanks

## Replies

### Reply by Anonymous User

This should work

```
topics = data.filter(function(item, index, data) {   for (var i = 0; i <data.length; i++) {      if (item.topicId=== data[i].topicId) break;   }   return index === i;}).map(function (item) {    return {        id: item.topicId,        name: item.topicName    };});If duplicate entries are equal, you can simplify filter functiondata.filter(function(item, index, data) {      return data.indexOf(item)=== index;})
```


---

Original Source: https://www.mindstick.com/forum/12686/how-to-remove-duplicate-entries-in-array

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
