Matt Cashatt
Matt Cashatt

Reputation: 24208

Using LoDash, how do I integrate a function into a _where method?

I have an array of objects that each have a date property. For some of the objects, the "Date" property is blank. I want to remove those from my object so that my view doesn't end up with entries containing NaN for the date.

Here is what I have tried:

_.where(data, { 'Date': d.Date instanceof Date && isFinite(d) })

AND

_.where(data, function(d) {
                        return d.Date instanceof Date && isFinite(d.date);
                    });

Both return 0 results however.

Upvotes: 0

Views: 126

Answers (1)

Bergi
Bergi

Reputation: 664484

You don't want to use where that "performs a deep comparison to the given property object" , but filter that uses a callback.

Upvotes: 1

Related Questions