javascript 为什么 lodash `_.all([true, true, true], true);` 返回 `false`?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30900646/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why does lodash `_.all([true, true, true], true);` return `false`?
提问by Victor S
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);
由于以下似乎没有做到:
_.all([true, true, true], true);
it returns: false
?
它返回:false
?
回答by Sebastian Dominguez
You should re-read the _.every(collection, [predicate=_.identity])
api docof lodash. The issue with your code is the second param you are passing. Remove it and it works
你应该重新阅读lodash的_.every(collection, [predicate=_.identity])
api 文档。您的代码的问题是您传递的第二个参数。删除它,它的工作原理
> _.every([true, 'foo', 1])
true
> _.every([true, 'foo', 1, 0])
false