关于数组 every 返回值 问题

关于数组 every 返回值

问题:

当this.dataList 为[]数组 , this.setOfCheckedId size为0 时 ,下列代码会返回true


 
this.checked = this.dataList.every(({ id }) => this.setOfCheckedId.has(id));
 
 

解答:

这是因为 every() 方法是用来检测数组中的每一个元素是否都符合特定条件,如果数组为空,则没有元素需要检测,因此函数返回 true。
在这种情况下,dataList 是一个空数组,因此没有元素需要检测,every() 方法返回 true,表示该数组中的每个元素都符合特定条件。

猜你喜欢

转载自blog.csdn.net/weixin_44216637/article/details/129933845