测试动态项目列表条件的最佳方法?

Best way to test conditions on a dynamic list of items?

首先,如果标题不是 100% 准确,我们深表歉意。

我有问题。

我在列表 A 中有一个项目的动态列表,项目的数量可以在 1-50 之间:

item1
item2
item3

我需要一个循环遍历这些项目的函数,检查每个项目的条件是否为真,如下所示:

if(item1 && condition) continue

创建此 function/algorithm 的最佳方法是什么?由于列表不是静态的,我不能像这样硬编码条件:

if(item1 && condition) continue
if(item2 && condition) continue
if(item3 && condition) continue

提前致谢

编辑:如果至少有一个条件为真,我希望函数 return 为真。

使用Array#some.

The some() method tests whether at least one element in the array passes the test implemented by the provided function. It returns true if, in the array, it finds an element for which the provided function returns true; otherwise it returns false. It doesn't modify the array.

let result = arr.some(element => predicate(element));