How can I check if all elements of an array are truthy or falsey.
Since the following doesn't seem to do it:
_.all([true, true, true], true);
it returns: false
?
Because they don't represent equally convertible types/values. The conversion used by == is much more complex than a simple toBoolean conversion used by if ('true') . So given this code true == 'true' , it finds this: "If Type(x) is Boolean , return the result of the comparison ToNumber(x) == y ."
Lodash's find() function returns the first element of a collection that matches the given predicate .
get() method in Lodash retrieves the object's value at a specific path. If the value is not present at the object's specific path, it will be resolved as undefined . This method will return the default value if specified in such a case.
falsey() Method. The Lodash _. falsey() method checks whether the given value is falsey or not and returns the corresponding boolean value. A falsey value is one that means false in a boolean context.
You should re-read the _.every(collection, [predicate=_.identity])
api doc of lodash. The issue with your code is the second param you are passing. Remove it and it works
> _.every([true, 'foo', 1])
true
> _.every([true, 'foo', 1, 0])
false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With