- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Remove/ filter duplicate records from array - JavaScript?
Let’s say the following are our records with some duplicate values −
var objectOfNationality = [ { nationality: "Indian" }, { nationality: "American" }, { nationality: "Emirati" }, { nationality: "Indian" }, { nationality: "American" } ];
Example
To remove duplicate records, use the concept of Set().Following is the code −
var objectOfNationality = [ { nationality: "Indian" }, { nationality: "American" }, { nationality: "Emirati" }, { nationality: "Indian" }, { nationality: "American" } ]; function removeOrFilterNationality(objectOfNationality) { return Array.from(new Set(objectOfNationality.map(tempObject => tempObject.nationality))); } console.log(removeOrFilterNationality(objectOfNationality));
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo228.js.
Output
The output is as follows −
PS C:\Users\Amit\JavaScript-code> node demo228.js [ 'Indian', 'American', 'Emirati' ]
- Related Articles
- Remove elements from array using JavaScript filter - JavaScript
- How to remove duplicate elements from an array in JavaScript?
- Using recursion to remove consecutive duplicate entries from an array - JavaScript
- Remove the duplicate value from array with images data in JavaScript
- Remove duplicate items from an array with a custom function in JavaScript
- Using recursion to remove consecutive duplicate entries from an array in JavaScript
- JavaScript Remove non-duplicate characters from string
- How to remove duplicate property values in array – JavaScript?
- Implement MySQL conditional GROUP BY with NOT IN to filter records from duplicate column values
- Filter null from an array in JavaScript?
- How to redundantly remove duplicate elements within an array – JavaScript?
- Removing duplicate objects from array in JavaScript
- How do I recursively remove consecutive duplicate elements from an array?
- How to remove Duplicate Records except a single record in MySQL?
- JavaScript Remove random item from array and then remove it from array until array is empty

Advertisements