I have an array of objects:
var arr = [{id:1, name: 'frank', type: 'great'}, {id:2, name: 'john', type: 'good'}, {id:3, name: 'mark', type: 'great'}, {id:4, name: 'mary', type: 'bad'}];
At some points, I need to print 3 different html-elements. In each one of this elements there will be a list of names that have the same "type".
I could make 3 different iterations where I go through all the items. But I wonder if there is a better way. The best I came with is to "filter" this array for each iteration. Even if I still will loop 3 times, maybe its a better way to do this, as you only go through the elements in the array that you really are interested of.
Im not really sure how to filter this. Im using angular.js. If not, I could use plain javascript. Or is there a better solution to this?
*****EDIT*****
Thanks to duffy for the advice on filter-function. I maybe require too much, but the thing is this:
There is an .html that now contains a div like this:
<div ng-repeat="person in peopleContainer.get_people()">
peopleContainer is a factory in the services.js-file. This factory function contains both the array with all the people and the functions to add one person/return the array with all the people.
Now (forget about filtering) the ng-repeat directive above doesn't seem to work. When I add a new person I can see that this person has been added to the array. But nothing happens in the div-container. No ng-repeat happens. Could this be because the array with people is located in the service.js-file? If yes: is there a way to work around this?