📜  没有重复的回调 javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:16.634000             🧑  作者: Mango

代码示例1
function myFunction(myArray, callBack){

 var unique = myArray.filter(function(item, pos) {
   //validates whether the first occurrence of current item in array
   // equals the current position of the item (only return those items) 
   return myArray.indexOf(item) == pos;
 });

 //wrap your result and pass to callBack function 
 callBack(unique);

}