I have an array of objects as myData which consists of the below JSON structure:
const data = {
myData: [
{ Type: 'REAL', Tenure: '12', Name: 'WEBPAGE' },
{ Type: 'REAL', Tenure: '24', Name: 'SERVER' },
{ Type: 'REAL', Tenure: '12', Name: 'WEBPAGE' },
],
};
I want to get rid of duplicate entries by keeping performance in mind as this array could be of length 1000+ using Javascript.
The Expected Output that I am looking for is as follow since myData[0] && myData[2] are duplicate here:
const result = {
myData: [
{ Type: 'REAL', Tenure: '24', Name: 'SERVER' },
{ Type: 'REAL', Tenure: '12', Name: 'WEBPAGE' },
],
};
Sajeeb Ahamed
6,4482 gold badges23 silver badges36 bronze badges
-
First of all, How do you consider that two objects are duplicates? Are you matching all properties or just specific property?DecPK– DecPK2021年08月09日 06:30:14 +00:00Commented Aug 9, 2021 at 6:30
1 Answer 1
You can use Lodash uniq function for more information please check https://lodash.com/docs/3.10.1#uniq
answered Aug 9, 2021 at 6:35
Shafqat Jamil Khan
1,0371 gold badge9 silver badges17 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Explore related questions
See similar questions with these tags.
lang-js