[removed] filter array of objects by array of strings

后端 未结 4 1100
臣服心动
臣服心动 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:31

    If you want them in the order of the array of string then

        var result = [];
    kpis.map((item) => {
        const matchedObject = a.find(
            (option) => option.id === item
        );
        result.push(matchedObject);
    });
    

提交回复
热议问题