Solution 1 :

Use your seen object as a counter instead of just setting true, then check the count on each row iteration.

I’m not 100% clear on what you expect the behavior to be so am appending any rows to duplicate table that already have two matches

function reoveDuplicateFramTable() {
  $("#duplicateData").empty();
  var seen = {};
  $('#Data tr').each(function() {
    var txt = $(this).text().trim();
    seen[txt] = (seen[txt] || 0) + 1

    if (seen[txt] > 2) {
      $("#duplicateData").append(this)
    } 
  });
}

reoveDuplicateFramTable()
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
  <tbody id="Data">
    <tr>
      <th>1</th>
    </tr>
    <tr>
      <th>1</th>
    </tr>
    <tr>
      <th>1</th>
    </tr>
    <tr>
      <th>2</th>
    </tr>
    <tr>
      <th>2</th>
    </tr>
    <tr>
      <th>3</th>
    </tr>
  </tbody>
</table>

<h3>Duplicates</h3>
<table>
  <tbody id="duplicateData">
    <tr>
      <th>1</th>
    </tr>
    <tr>
      <th>2</th>
    </tr>
  </tbody>
</table>

Solution 2 :

// loop through table
$("#Data tr").each(function() {
// find duplicates that contains same text
   let elements = $("#Data tr:contains("+$(this).text()+")")
//check if length is greater than 2 then remove those add in duplicates table
   if (elements.length > 2){ 
// add duplicate element
      $("#duplicateData").append($(this).html())
// remove all duplicates from #Data 
      elements.remove()
   }
})
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<table id="Data">
<tr> <th>1</th>  </tr>
<tr> <th>1</th>  </tr>
<tr> <th>1</th>  </tr>
<tr> <th>2</th>  </tr>
<tr> <th>2</th>  </tr>
<tr> <th>3</th>  </tr>
</table>

<table id="duplicateData">
</table>
</body>

Problem :

I have two table one for the data and the second one for duplicate data in first table

Imagen that inside first table :

<tbody id="Data">
<tr> <th>1</th>  </tr>
<tr> <th>1</th>  </tr>
<tr> <th>1</th>  </tr>
<tr> <th>2</th>  </tr>
<tr> <th>2</th>  </tr>
<tr> <th>3</th>  </tr>
</tbody>

I use this function to remove duplicate data

function reoveDuplicateFramTable(){
 $("#duplicateData").empty(); 
 var seen = {};
 $('#Data tr').each(function() {
 var txt = $(this).text();
 if (seen[txt]){  $("#duplicateData").append($(this)) }
  else{ seen[txt] = true  }
});}

and the second table will be like this:

<tbody id="duplicateData">
  <tr> <th>1</th>  </tr>
  <tr> <th>2</th>  </tr>
</tbody>

how about if i wand just to remove duplicate data if they repeated 3 time?
the second table be like this:

<tbody id="duplicateData">
 <tr> <th>1</th>  </tr>
</tbody>

is that possible in Jquery?

Comments

Comment posted by Ayaz Alavi

check :contains(value) in jquery and calculate output length for each element found.

Comment posted by bandar hamed

sorry .. I’am beginner could you explain that by edit in my code?

Comment posted by charlietfl

Code wise this appears simpler than a tracking object but all those extra DOM queries are a lot more expensive, especially on larger table

Comment posted by Ayaz Alavi

@charlietfl thanks, you are absolutely right but give the fact that he is a beginner I think solution will work for test projects.

Comment posted by charlietfl

Best practices shouldn’t be determined by level of understanding

By