我想循环下面的代码。如何将列名保留在数组中并通过循环返回? return Students.filter((singleItem) => { singleItem["id"].toLowerCase().includes(value.toLowerCase()) || singleItem["name"].toLowerCase().includes(value.toLowerCase()) || singleItem["class"].toLowerCase().includes(value.toLowerCase()) });例如: var columns= ["id","name","class"]; return Students.filter((singleItem) => { columns.map(data=>{ singleItem[data].toLowerCase().includes(value.toLowerCase()); //I have to use the "||" operation here. How can I use it in the loop? }) });
1 回答
PIPIONE
TA贡献1829条经验 获得超9个赞
您可以迭代给定的键并使用 提前退出Array#some
。
var columns = ["id", "name", "class"];
return Students.filter(singleItem =>
["id", "name", "class"].some(key =>
singleItem[key].toLowerCase().includes(value.toLowerCase())
)
);
添加回答
举报
0/150
提交
取消