JS 数组去重

Array.prototype.unique3 = function(){ //数组去重
var res = [];
var json = {};
for(var i = 0; i < this.length; i++){
if(!json[this[i]]){
res.push(this[i]);
json[this[i]] = 1;
}
}
return res;
}

$scope.selectedShops=$scope.selectedShops.unique3();

js 数组遍历

for(j in $scope.aggShops){
if ($scope.aggShops[j].siteId != "ALL") {
$scope.siteIds.push($scope.aggShops[j].siteId);
};
}

2222222222222

$scope.aggShops.forEach(function(e){
if (e.siteId != "ALL") {
$scope.siteIds.push(e.siteId);
};
console.log(e);
})

posted @ 2015-07-27 16:29  仗剑天涯只为卿  阅读(138)  评论(0编辑  收藏  举报