[英]How to create a comparison expression using loop in Javascript?
我有以下比較表達式:
return (!item['a'] || filter['a'])
&& (!item['b'] || filter['b'])
&& (!item['c'] || filter['c']);
但是,假設我有很長的字符串列表要與&&
進行比較,例如
var myList = ['a','b','c','d']
for(var i in myList) {
//(!item[myList[i]] || filter[myList[i]]) How am I suppossed to && this for every iteration?
}
對於每次迭代,我如何假設&&
表達式?
您可以使用use .every
:
return ['a', 'b', 'c', 'd'].every(prop => !item[prop] || filter[prop]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.