Is there a way to simplify this code with the use of Object.entries()? I want to remove new Map().
const err = [{
'id': 1,
'error': ["Error 1", "Error2"]
}]
const warn = [{
'id': 1,
'warning': ["Warn 1", "Warn 2"]
}]
const map = new Map();
err.forEach(item=> map.set(item.id, item));
warn.forEach(item=> map.set(item.id, {...map.get(item.id), ...item}));
const combined = Array.from(map.values());
console.log(combined)
Tried:
const map = new Map(Object.entries(err));
warn.forEach(item=> map.set(item.id, {...map.get(item.id), ...item}));
const combined = Array.from(map.values());
console.log(combined)
The output should still be the same
[{
'id': 1,
'error': ["Error 1", "Error2"],
'warning': ["Warn 1", "Warn 2"]
}]