[removed] filter array of objects by array of strings

后端 未结 4 1094
臣服心动
臣服心动 2020-12-03 11:54

I wonder if there is a more elegant way of doing this. Suppose i have an array of objects like this:

a = [
  {
    \"id\": \"kpi02\",
    \"value\": 10
  },
         


        
4条回答
  •  暖寄归人
    2020-12-03 12:36

    You can use indexOf in filter, like this

    var res = a.filter(function (el) {
      return kpis.indexOf(el.id) >= 0; 
    });
    

    Example

提交回复
热议问题