title: How to swap particular row among list of row based on value scanned in text box in jquery
body: <p>I'm developing a web application in that I'm generating table row dynamically based on value entered in text box. Only one condition, if I enter same value twise (one after another), it should not add row. If I enter 10 different values and at 10th time if I enter the value which I entered previously that row should come to top in the table. (It should not add again). </p>
  
  <p>For example I am entering value like <code>1,2,3,4,5,6,7,8,9,10</code> and 11th time I am entering value 1 then in that table 1 row should come at top <code>(1,10,9,8,7,6,5,4,3,2)</code>. </p>
  
  <p>If I entered 1,1 then it should add row only one time. Please help me to complete this. Thanks in advance.</p>
  
  <pre><code>$(document).ready(function(){
      var WholeString="";
  
      /*To Search Shipment id through webservice: Begin */    
      $('#searchkey').change(function(){
          Allboxes=new Array();
          Allboxes[0]=0;
  
              $.ajax({
              type : 'POST',
              url : '@routes.Application.searchkey()',
              data : {
                  searchkey : $(this).val(),
                  orgname: 'FB'
              },
              success : function(data) {
                  console.log("success"+data);
                  var arr = data.split('&amp;');
  
  
                  if((arr[0]!="null")&amp;&amp;(arr[1]!="null")&amp;&amp;(!WholeString.contains(arr[0])))
                  {
                      WholeString=WholeString+"::"+arr[0];
  
                      var table='&lt;tr  class="active" style="height:40px;"&gt;';
                      table += '&lt;td&gt;&lt;input type="checkbox" class="radio" name="name1" value="1" checked /&gt;&lt;/td&gt;';
                      table += '&lt;td&gt; &lt;button type="button" class="btn btn-primary btn-sm dark_button width-150px"&gt;'+arr[0]+'&lt;/button&gt;&lt;/td&gt;';
                      table += '&lt;td&gt;'+arr[1]+'&lt;/td&gt;';
                      table+='&lt;td&gt;&lt;i  style="color:green;font-size:18px" class="fa fa-check"&gt;&lt;/i&gt;&lt;/td&gt;';
                      table += '&lt;/tr&gt;';
  
              // append table in box_content
                  $("#boxnumberarea").append(table);
  
              // creates tbody and append to last inserted table
                  var $tbody = $('&lt;tbody&gt;').appendTo('#boxnumberarea table:last');
                  Allboxes[0]=arr[0];
                  }
              },
              error : function() {
                  console.log("failed");
  
              }
                });
           $(this).val('');
  
  
  /*To Search Shipment id through webservice: End */  
      });
      if (!('contains' in String.prototype)) String.prototype.contains = function (str, startIndex) {
          return -1 !== String.prototype.indexOf.call(this, str, startIndex);
      };
  });
  
    &lt;/script&gt;
  </code></pre>
  
  <p>Assume inside tbody that ajax portion is been appending.Now code will not allow duplicate value. Along with that i want above feature as well.</p>