Time for another post on lodash this one is on the lodash intersection method. The _.intersection method will create an array of values that are in all the given arrays using the lodash _.eq method also known as same value zero for comparisons.
So for a basic example of the lodash intersection method, if I just have to arrays of primitives I can just pass those arrays as arguments to the lodash intersection method. The result that is returned will then be an array of values that are in all of those given arrays.
So arrays of primitives are nice, but any real project will often involve arrays of objects. There are two other methods in lodash called _.intersectionBy and intersectionWith than can be used to work with more complex situation sin which collection of objects are involved.
when working with arrays of objects things can get a little more involved. However if I do just want to compare a uniform object property then the lodash _.intersectionBy method can be used.
Still you might start out with something like this that will work fine for comparing just two arrays at least for all the testes that I have do with this thus far.
If I where to use just equality or identity for the comparisons then the NaN value will not be included. This is of course one of the reasons why we have yet another way to go about making comparisons on top of that of the two general operators that come to mind when comparing two values.