Advertisement
pharmokan

JS left join of 2 Obj arrays that share a common key+value

Feb 13th, 2022
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. let key = 'id';
  2. let arr1 = [
  3. { id: "9762 /3/a/z/group( + ) / ()/", date: "2017-01-24" },
  4. { id: "abdc4051", date: "2017-01-22" }
  5. ];
  6.  
  7. let arr2 = [
  8. { id: "9762 /3/a/z/group( + ) / ()/", match:true},
  9. { id: "abdc4051", match: true}
  10. ];
  11.  
  12. arr1.forEach((x,y)=> {
  13. let a = arr2.find(d => x[key] == d[key]);
  14. if(a && (a[key] == x[key])) arr1[y] = { ...arr1[y], ...a }
  15. })
  16. //
  17. console.log(arr1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement