Here's an example of an array I have:
vm.names = ['A', 'A', 'B', 'B', 'C', 'C', 'C'];
To count the items in the array, I currently use this approach:
vm.a = [];
vm.b = [];
vm.c = [];
for (var i = 0; i < vm.names.length; i++) {
if (vm.names[i] === 'A') {
vm.a.push(vm.names[i]);
}
if (vm.names[i] === 'B') {
vm.b.push(vm.names[i]);
}
if (vm.names[i] === 'C') {
vm.c.push(vm.names[i]);
}
}
After counting, I render it in HTML like this:
{{ vm.a.length }} //2
{{ vm.b.length }} //2
{{ vm.c.length }} //3
However, I feel that there may be a better way to achieve this. If you have any suggestions, please let me know.