My JSON Object
$scope.selectedItems ={
"RECORDS": [
{
"Id": 23040035705987,
"arriveddate": "2015/04/24",
"expirationDate": null,
"replacedDate": null,
"processDate": "2015/04/24"
},
{
"Id": 23070041800654,
"arriveddate": "2015/04/24",
"expirationDate": null,
"replacedDate": null,
"processDate": "2015/04/27"
},
{
"Id": 23040035705984,
"arriveddate": "2015/04/24",
"expirationDate": null,
"replacedDate": null,
"processDate": "2015/04/24"
},
{
"Id": 23040035705983,
"arriveddate": "2015/04/24",
"expirationDate": null,
"replacedDate": null,
"processDate": "2015/04/24"
}
]
}
what i am trying
For every unique process dates i have i need the corresponding ids in a separate object in the below mentioned object the process date 24/04/2015 matches with the ids ending with 83,84,87 and the process date 27/04/2015 matches with the id ending with 54
My expected JSON object
{
"processDate": [
"2015/04/24",
"2015/04/27"
],
"Id": [
[
23040035705983,
23040035705984,
23040035705987
],
[
23070041800654
]
]
}
how i am trying
angular.forEach($scope.selectedItems.RECORDS, function ( item ) {
$scope.ProcessDate = item.processDate;
if($scope.processDatesSelected.indexOf($scope.ProcessDate) == -1){
$scope.processDatesSelected.push($scope.ProcessDate);
}
if($scope.processDatesSelected.indexOf($scope.ProcessDate) != -1 && $scope.id.indexOf(item.Id) == -1 ){
$scope.id.push(item.Id);
}
});
$scope.changesSelected.push({processDate:$scope.processDatesSelected,Ids:$scope.id});
console.log(JSON.stringify($scope.changesSelected));
Issue is with the id not mapping accordingly , i have created a plunker for the same (http://plnkr.co/edit/mkLXdOKayaqyDDDheFeu?p=preview) Any help would be appreciated.