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
Post a Comment