数组对象去重

$scope.doctorDatas = function () {
       
        var doctorLast = null;
        var doctorNew = null;
        if(angular.fromJson($stateParams.echoData) != null){
            doctorLast = angular.fromJson($stateParams.echoData).doctors;
        }
        doctorNew = angular.fromJson($stateParams.doctors);
        if(doctorLast != null){
            angular.forEach(doctorNew,function (data,index,array) {
                doctorLast.push(doctorNew[index]);
            })
            var unique = {};
            doctorLast.forEach(function(a){ unique[ JSON.stringify(a) ] = 1 });
            doctorLast= Object.keys(unique).map(function(u){return JSON.parse(u) });
            $scope.doctors = doctorLast;
        }else{
            $scope.doctors = doctorNew;
        }

    }
let newArr=[];//去除空对象
for(let j in arr){
  for(let prop in arr[j]){
      if(prop!=''||arr[j][prop]!=''){
          newArr.push(arr[j]);
      }
  }
};

 

posted @ 2017-06-22 16:38  yangfei969  阅读(195)  评论(0编辑  收藏  举报