javascript - Why does lodash `_.all([true, true, true], true);` return `false`? - Stack Overflow

How can I check if all elements of an array are truthy or falsey.Since the following doesn't seem

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?

Share Improve this question asked Jun 17, 2015 at 19:26 Victor SVictor S 5,1325 gold badges46 silver badges63 bronze badges 2
  • 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
Add a comment  | 

1 Answer 1

Reset to default 36

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1738165075a4028715.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信