javascript - Best way to remove the object from an array using AngularJs -


i have array of objects. want remove multiple objects array.

i have used below code working absolutely fine, need check guys if there better way or fine.

i have done angularjs , js.

orders main array on operations performed. order array of selected items remove main array orders

$scope.order = {}; $scope.removeorders = function () {         angular.foreach($scope.order, function (data) {             (var = $scope.orders.length - 1; >= 0; i--) {                 if ($scope.orders[i].name == data.name) {                     $scope.orders.splice(i, 1);                 }             }         });         } 

you can make quite bit shorter using filter:

$scope.removeorders = function () {     $scope.orders = $scope.orders.filter(function(order){         return !$scope.order.some(function(remove){             return remove.name === order.name;         });     }); // remove order $scope.orders, if it's name found in $scope.order }; 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -