Reputation: 283
With
var a = _.where(list, {key: "value"});
if (a) console.log("exists");
the conditional doesn't seem to work, but if I change to if (a != "")
it does. Since a = [] when not finding anything I'm using if (a.length > 0)
, but just curious why it works with an empty string and then not with the original example. Isn't an empty string in JS a falsy?
Upvotes: 0
Views: 204
Reputation: 144689
Yes, an empty string is a falsy value in JavaScript, but where
method returns an array and an array is an object which is not a falsy value, even empty arrays are truthy.
[] != '' // false
!![] // true
Upvotes: 1