Advertisement
pharmokan

JS match skus

Mar 29th, 2022
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. let a = [{"sku":"a"},
  2. {"sku":"b"},
  3. {"sku":"c"},
  4. {"sku":"d"},
  5. {"sku":"e"},
  6. {"sku":"ff"},
  7. {"sku":"gg"}]
  8.  
  9. let b = [{"sku":"k"},
  10. {"sku":"z"},
  11. {"sku":"d",'fig':3},
  12. {"sku":"b","fig":5},
  13. {"sku":"a"},
  14. {"sku":"c"}];
  15.  
  16. let __KEY__ = Object.keys(a[0])[0]
  17.  
  18. a.forEach((x,i)=> {
  19. let k = b.find(z=> z[__KEY__] == x[__KEY__])
  20. if(k) {
  21. a[i]._MATCHED = k[__KEY__]
  22. a[i] = {...a[i],...k}
  23. }
  24. });
  25.  
  26. console.log(a)
  27.  
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement