Closed this issue 7 years ago · 1 comments
//数组去重:利用key的唯一性 function removeRepetition (a) { var rs = [],hash = {}; for(var key in a){ if(a[key]!=null && !hash[a[key]]){ rs.push(a[key]); hash[a[key]] = true; } } return rs; }
function removeRepetition (a) { var rs = [],hash = {}; for(var key in a){ if(a[key]!=null && !hash[a[key]]){ rs.push(a[key]); hash[a[key]] = true; } } return rs; }
1.感觉比我那个麻烦,我也没习惯对数组使用 for-in循环。 2.而且,如果是一维数组[1,2,3,4,5,6,9,5],这种,a[key]应该不行