I have a array like this which has same tid i want to compare this array and display error message as duplicate ID is present
Asked
Active
Viewed 420 times
0
-
1That is a JavaScript array of JavaScript objects. Not JSON. – Turnip Feb 11 '19 at 13:53
-
Possible dupe: https://stackoverflow.com/questions/6237537/finding-matching-objects-in-an-array-of-objects – Turnip Feb 11 '19 at 13:56
-
1If the following is true then you don't have duplicates: `data.length === new Set(data.map(d=>d.Tid)).size` – HMR Feb 11 '19 at 14:00
-
@HMR this is showing false – chethu Feb 11 '19 at 14:02
-
If the following is true then you **don't** have duplicates, if it shows false then you do have duplicates. – HMR Feb 11 '19 at 14:03
-
@HMR thanks i got solution for based on your condition – chethu Feb 11 '19 at 14:17
1 Answers
1
Something like this should do it:
array.forEach(function(e,i){
for (var j = i+1; j < array.length; j++) {
if (e.Tid == array[j].Tid) {
// ids match, do something
}
}
});

cmac
- 3,123
- 6
- 36
- 49