There is a request for some information:

<script type="text/javascript"> setInterval(function() { $.getJSON('/test.php', function(data) { alert(data.num); // Π½Π΅ΠΊΠΈΠ΅ значСния }); }, 2000); </script> 

For the sake of interest, if 5 identical values fall out in num (for example, alert (1) drops out 5 times), then 4 needs to be deleted and output 1. And all this in JS.

    2 answers 2

    As an option, write the numbers that have fallen into the array and check before output that this has not happened before (using jQuery)

     var nums = []; setInterval(function() { $.getJSON('/test.php', function(data) { if ($.inArray(data.num, nums)) { alert(data.num); // Π½Π΅ΠΊΠΈΠ΅ значСния nums.push(data.num); } }); }, 2000); 

    If you mean that you can not display the same numbers in a row, then just remember the last number and compare with it before displaying

      I would do this:

       function remove (data){ for(var i = 0; i < data.length; i++) for(var j = i+1; j < data.length; j++) if(data[i] == data[j]) data.splice(j, 1); return data; } 

       var data = ['data1',2,3,2,1,'data4',5,6,'data3',8,9,'data4',5,2,'data1']; console.log(remove(data)); //["data1", 2, 3, 1, "data4", 5, 6, "data3", 8, 9]