I am looking to filter out specific objects from an array based on a condition and create a new array with those filtered objects. Currently, I am struggling with the code snippet provided below:
The goal is to only copy objects from the existing 'orders' array to the 'temp' array where the 'status' key matches 'completed'. However, using angular.copy seems to be copying all objects instead of just the ones that meet the condition.
--------html-----
<body ng-app ="myModule">
<div ng-controller="myController">
<div ng-repeat="order in temp">
{{order.id}} -- {{order.status}} -- {{order.name}}
</div>
</div>
</body>
-------xxxx------
-------JS----------
<script>
var myModule = angular.module('myModule', []);
myModule.controller('myController', function($scope) {
$scope.orders = [
{id: '101' , status : 'completed' , name: 'Jacopo' } ,
{id: '102' , status : 'Rejected' , name: 'Dan' } ,
{id: '103' , status : 'created' , name: 'Erick' }
] ;
$scope.temp = [ ] ;
angular.forEach($scope.orders , function(key,value){
if(key.status == 'completed') {
angular.copy($scope.orders,$scope.temp)
}
} );
} ) ;
</script>
------xxx--------