$scope.$on("event:post_highlighted", function(event, post, val) { var found= false; var position= null; angular.forEach($scope.highlights, function(value, key) { if(post.pid== value.pid) { found= true; position= key; } }); if(val === 0 && found) { $scope.highlights.splice(position, 1); } else if(val === 1 && !found){ $scope.highlights.unshift(post); } }); $scope.$on("event:post_favourited", function(event, post, val) { var found= false; var position= null; angular.forEach($scope.favourites, function(value, key) { if(post.pid== value.pid) { found= true; position= key; } }); if(val === 0 && found) { $scope.favourites.splice(position, 1); } else if(val === 1 && !found){ $scope.favourites.unshift(post); } });