如何使用javascript

时间:2018-09-19 05:19:29

标签: javascript arrays angular

我需要根据名称属性过滤b,并且只需要b中的那些列

     a = [{'id':'1', 'name':'a1'}, {'id':'2', 'name':'a4'}]

     b = [{'a1':'2', 'a2':'3','a3':'2', 'a4':'3' }, {'a1':'5', 
        'a2':'7','a3':'9', 'a4':'6' } ]

     c = [{'a1':'2','a4':'3' }, {'a1':'5','a4':'6' }]

1 个答案:

答案 0 :(得分:0)

   let filterData = [];
   b.map(data => {
      let obj = {};
      a.forEach(cols => {
        obj[cols.name] = data[cols.name]
      })
      filterData.push(obj)
    });