admin管理员组文章数量:1026989
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
?
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
?
1 Answer
Reset to default 36You 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
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
?
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
?
-
5
lodash.com/docs#every suggests you are not using this function correctly (to start off, it's no longer
_.all
) – Mike 'Pomax' Kamermans Commented Jun 17, 2015 at 19:29 -
1
_.every([true, true, true]);
Should work. – Bastian Hofmann Commented Jun 17, 2015 at 19:33
1 Answer
Reset to default 36You 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
本文标签: javascriptWhy does lodash all(truetruetrue) return falseStack Overflow
版权声明:本文标题:javascript - Why does lodash `_.all([true, true, true], true);` return `false`? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1738165073a1552551.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
_.all
) – Mike 'Pomax' Kamermans Commented Jun 17, 2015 at 19:29_.every([true, true, true]);
Should work. – Bastian Hofmann Commented Jun 17, 2015 at 19:33