where for arrays of objects
Problem
You want to get an array of objects that match your request for some properties
You have an Array of Objects, such as:
You want to filter with some properties, like cats.where({ age: 1}) or cats.where({ age: 1, favoriteFood: “mice”})
Solution
You can extend Array like this :
Discussion
This is an exact match. we could make it more flexible with a matcher function :
it’s more a method to deal with collection and it could be rename as “find” but popular libraries like underscore or lodash name it “where”.