So yes there is of course Array.find, and Array.find works just fine with Arrays:
It also works well with array like objects when used with call.
However _.find is a collection method, not an Array method. So in addition to working just fine with Arrays _.find works with plan old objects as well, even if they are not array like.
Also there is the built in iteration methods that can come in handy. The potential for better backward compatibility with old versions of IE if for some reason that is a concern. Also this is a lodash post, so…
The lodash _.find method works not just with Arrays but also any object, so _.find is considered one of the many collection methods in lodash. So find can help solve that problem when it comes to choosing between using Arrays and plain old Objects, as in any case I can use _.find to get at what I want in an Object of any kind, not just an Array.
So the first argument that is given to _.find is a collection, which can be an Array, an Array like object, just a plain old Object, and even Strings.
The second argument that is given to _.find is an iteration method, or some kind of short hand for such a method. This method can have three arguments, the first of which is the current element in the collection that is being looked at. In addition the second argument is the current index, and the last argument is a reference to the collection that was given.
In the body of the iteration method, if what is returned by the method evaluates to true then, then that will count as the element being found.
As shown above I can make my own methods that are used to define the terms of whether or not an element in a collection is what it is that I am looking for. I can of course make a method that returns a iteration method that _.find can use. However I might not even have to do that if such a method is in lodash to begin with, and there are even some shorthands that can be used in _.find that allow for me to not even have to call the lodash method directly.
In addition to shorthands for _.property there are also shorthands for _.matches _.matchesProperty.
This lodash method can accept a third argument that is the index where to start looking in the collection.
So _.find will help with returning an element in an array, rather than it’s index. So if you have an array of objects and you want to find a single object in the array by a certain key value pare _.find is the right tools for the job.
You do not have to give an object, you can also use a function like this.
In lodash there is the _.findIndex method, that works just fine with Arrays, as it is an Array method. However it will not work with Objects in general, as it is not a collection method. It is possible to use _.find to get the index of an element in an Array, or the key of a property in any Object. As you might have read earlier in this post the second argument that is given in the iteration method is the index, or key value if it is a plain Object.
Find is fairly robust, of course it can be used with an array of primitives.
However _.find can be used on a single stand alone String as well
Many of the methods in lodash provide functionality that is very similar to certain native methods, but often they do bring a little something more to the table.
I have updated this post a few times now, and I will likely update this post again in the future once again at some point. If you are in the mood check out my other posts on lodash.