My array Looks like this
var List = [
{qid: 1, ID: 1, text: "XXX",...},
{qid: 1, ID: 2, text: "XXX",...},
{qid: 1, ID: 3, text: "XXX",...},
{qid: 2, ID: 4, text: "XXX",...},
{qid: 2, ID: 5, text: "XXX",...},
{qid: 3, ID: 6, text: "XXX",...},
{qid: 3, ID: 7, text: "XXX",...},
{qid: 3, ID: 8, text: "XXX",...},
];
I want to query the array so that the final list looks like this
var FinalList = [
{qid: 1, ID: 3, text: "XXX",...},
{qid: 2, ID: 5, text: "XXX",...},
{qid: 3, ID: 8, text: "XXX",...},
];
qid can have multiple ID but the last entry will be the one selected for the FinalList[] array
I want to use something like group by on qid and get last row entered based on qid in angularcontroller.js.
I tried using the reduce function but it does not give me exactly what i want
its been just a month since I have started using angularjs any help will be greatly appreciated
Addition:
I tried doing this
angular.forEach($scope.selectedList, function (item) {
var found = $filter('filter')($scope.selectedList, { QuesID: item.qid});
$scope.FinalList .push(found[found.length - 1]);
$scope.List = $scope.List .filter(function (o1) {
return !$scope.List.some(function (o2) {
return o1.qid=== o2.qid;
});
});
});
I get the first item not the subsequent