JSFiddle - React, Tailwind, and code Playground

JavaScript

//the code
var array = [1,2,2,3,4,5,66,66];

for (var s in array) {
  alert(sort_unique(array)[s]);
}

//the function
function sort_unique(data) {

  var result = [];

  data.forEach(function(element, index) {
  // Find if there is a duplicate or not
    if (data.indexOf(element, index + 1) > -1) {
      // Find if the element is already in the result array or not
      if (result.indexOf(element) === -1) {
        result.push(element);
      }
    }
  });
 
  return result;
 
}