0

enter image description here

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

6
  • 1
    That is a JavaScript array of JavaScript objects. Not JSON. Commented Feb 11, 2019 at 13:53
  • Possible dupe: stackoverflow.com/questions/6237537/… Commented Feb 11, 2019 at 13:56
  • 1
    If the following is true then you don't have duplicates: data.length === new Set(data.map(d=>d.Tid)).size Commented Feb 11, 2019 at 14:00
  • @HMR this is showing false Commented Feb 11, 2019 at 14:02
  • If the following is true then you don't have duplicates, if it shows false then you do have duplicates. Commented Feb 11, 2019 at 14:03

1 Answer 1

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
     }
   }
 });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.