Angular: Empty Fiddle
http://angularjs.org/
by Nicolas PUJOL
HTML
<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-controller="MyCtrl"></div>
JavaScript
var myApp = angular.module('myApp', []);
function MyCtrl($scope) {
var masterList = [{
name: 'Jon',
age: 34
}, {
name: 'Steve',
age: 33
}, {
name: 'Mark',
age: 34
}, {
name: 'Jon',
age: 35
}];
var filterList = {
users: [{
username: 'Jon'
}, {
userName: 'Steve'
}, {
username: 'Mark'
}, {
username: 'Mike'
}],
ages: [{
age: 33
}, {
age: 34
}, {
age: 35
}, {
age: 36
}]
};
var countNamesList = {};
var countAgesList = {};
angular.forEach(masterList, function(value, index) {
if (!angular.isUndefined(countNamesList[masterList[index].name])) {
countNamesList[masterList[index].name] += 1;
} else {
countNamesList[masterList[index].name] = 1;
}
if (!angular.isUndefined(countAgesList[masterList[index].age])) {
countAgesList[masterList[index].age] += 1;
} else {
countAgesList[masterList[index].age] = 1;
}
});
console.log(countNamesList);
console.log(countAgesList);
}