{id: "A1", name: "test1"},
{id: "A2", name: "test2"}
];
let y = [
{id: "A1", description: "desc1"}
];
How can I combine them like a SQL inner join on 'id' attribute?
z <-- [
{id: "A1", name: "test1", description: "desc1"},
{id: "A2", name: "test2"}
]
?
I have troubles into doing that using map and reduce, so far I found this but I still have duplicates:
let z = x.map((item, i) => Object.assign({}, item, y[i]));
I also found a solution with forEach that wasn't really efficient, that's why I'm asking you. Thanks for help in advance.
didn't know ed sheeran did programming
If you want an efficient solution, you could make a Map<ID, object[]>, then go through that map and merge the object arrays
haha, you don't know how many people told me that phrase :O
Обсуждают сегодня