To use the _.filter methods the first argument that you give it is a collection, such as an array of numbers. The second argument you give is an iteratee method, that can be your own method, or one of the lodash iteratee methods such as _.matches, also some of those methods are built in. By collection a given object to the lodash filter method does not have to be an array, it can be any kind of collection object such as an array like object, or just a plain object with named rather than numbered keys. This is one of the main reasons why people like to use lodash over native methods as many of these methods do work a little different from native counterparts such as the array filter method that will just work with arrays, at least by itself anyway.
So for a basic example one might have a simple little demo in which I have an array of numbers that are negative and positive. For this example then I use _.filter to create a new array that is only the positive numbers in that array that are greater than that of zero. So then I just need to call the lodash filter method, pass the array of numbers are the first argument and then the function that I want to call for each element in this array. Inside the body of the function that I give to lodash filter I will want to return a Boolean value that is typically the result of some kind of expression, in this case the result of an expression that will be true of a current value is greater than zero.
Another kind of collection object that I will run into often is an array like object. What I mean by this is that I am dealing with an object that is formated like that of an array in the sense that it is a collection of key value pairs where each key is a numbed rather than named key, and there is a length property of the object that defines the max size of this collection in terms of elements. However one major difference between one of these array like objects and an array is that it is not an object that is an instance of the built in array class, therefor I can not just use an array prototype method off of such an object. However with the lodash filter method I can just pass this kind of object and I will get the same result as it it where an array.
So then the lodash filter method will work out of the box with arrays, and array like objects. However it will also work with the public keys of any object actually. This includes objects that are collections that are composed of named keys rather than numbered ones, and that do not have a length property.
When it comes to getting the array filter method to work with an array like object the function prototype methods are one way to go about doing so. These function prototype methods can be used to redefine what the value of the this keyword is inside the body of a class prototype method, including built in prototype methods such as the array filter method of the array prototype.
When it comes to working with a collection that is composed with named keys there are static methods like Object.keys and Object.values that can be used to create an array of public key names or values of any object. The object keys method will return an array of key names, and the object values method will return an array of values from a given source object. The filter method can then be called off of one of these arrays that are the return values of the Object values, or Object keys methods as it is an instance of an array.