$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]); } } };