JS arrays take intersection

the following two arrays exist

var a = [{convertFld: "a"},{convertFld: "b"},{convertFld: "c"},{convertFld: "g"}]
var b = [{a:1,b:2,c:3,d:4,e:5}]

I want to get

var c = [{a:1,b:2,c:3}]

how to implement it with ES6"s Set data structure?

Dec.03,2021

some of the words are not very clear

  1. b Why is it an array
  2. What is the relationship between
  3. and Set ? why use Set
var a = [{convertFld: "a"},{convertFld: "b"},{convertFld: "c"},{convertFld: "g"}]
var b = [{a:1,b:2,c:3,d:4,e:5}]
// 
Object.values(a).filter(a=>Object.keys(b[0]).includes(a.convertFld)).map(a=>({[a.convertFld]:b[0][a.convertFld]})).reduce((a1,a2)=>({...a1,...a2}))
{a: 1, b: 2, c: 3}```

clipboard.png


in fact, a map can handle it. I don't understand what you want to do with Set .

var a = [{convertFld: 'a'}, {convertFld: 'b'}, {convertFld: 'c'}];
var b = [{a: 1, b: 2, c: 3, d: 4, e: 5}];
var c = b.map(d => a.reduce((o, k) => (!(o[k.convertFld] = d[k.convertFld]) || o), {}));
console.log(c)

var a = [{id:'a'},{id:'b'},{id:'c'},{id:'f'}]
var b = [{a:1,b:2,c:3,d:4,e:5},{a:11,b:22,c:33,d:44,e:55}]
var c = b.map((item) =>{
    return a.reduce((k,m) => {
//        console.log(`k`,k,`m`,m,item.hasOwnProperty(m.id))
       item.hasOwnProperty(m.id) ? k[m.id] = item[m.id]: k
//        console.log(`k1`,k)
      return k
   },{})
})
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4725b-438ca.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4725b-438ca.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?