如何在循环中添加“或”运算?

我想循环下面的代码。如何将列名保留在数组中并通过循环返回?


 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?

  

   })


 });


慕妹3146593
浏览 97回答 1
1回答

PIPIONE

您可以迭代给定的键并使用 提前退出Array#some。var columns = ["id", "name", "class"];return Students.filter(singleItem =>    ["id", "name", "class"].some(key =>        singleItem[key].toLowerCase().includes(value.toLowerCase())    ));
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript