There is an array in which the objects are located.

PortalApi.searchServices(data) .then(function(get) { $scope.services = response; $scope.checkFavorites(get); if(response.length < 12){ $scope.services_new = false; }else{ $scope.services_new = true; } $scope.preLoader = false; }) 

It checks by ID to display only certain values, but as a result, duplicates are also displayed. I think to use .filter to go through the response and remove all objects in which the property isFavorite = false .

But when I try, an empty array returns to me:

 PortalApi.searchServices(data) .then(function(get) { //allFavorites $scope.checkFavorites(get); // $scope.services = response; function filterByFav(service) { $scope.services = response.map(service => { if (service.isFavorite == true) { return true; } }); } $scope.services = $scope.services.filter(filterByFav); // $filter('filter')(response, expression, comparator, anyPropertyKey); console.log($scope.services);//todo delete if(response.length < 12){ $scope.services_new = false; }else{ $scope.services_new = true; } $scope.preLoader = false; }) 

What is wrong or how to do it differently?

    1 answer 1

    I decided:

      PortalApi.searchServices(data) .then(function(get) { //allFavorites $scope.checkFavorites(get); function isFavoritTrue(service) { return service.isFavorite == true; } $scope.services = response.filter(isFavoritTrue); if(response.length < 12){ $scope.services_new = false; }else{ $scope.services_new = true; } $scope.preLoader = false; }) 
    • describe in the decision exactly how you decided. And why did it work - Grundy