js 获取数组重复的元素

//获取数组重复的元素
function refrain(arr) {
  var tmp = [];
  if(Array.isArray(arr)) {
    arr.concat().sort().sort(function(a,b) {
      if(a==b && tmp.indexOf(a) === -1) tmp.push(a);
    });
  }
  return tmp;
}
 
原文地址:https://www.cnblogs.com/zhaomeizi/p/9549347.html