I'm trying to get an array of objects into an object-format with the values as the keys of the new object.
Let's say I got this data:
const data = [
{
  key: "foo",
  value: "xyz",
  classLabel: "Test"
},
{
  key: "foo",
  value: "abc",
  classLabel: "Test"
},
{
  key: "bar",
  value: "aaa",
  classLabel: "Test"
}]
And the format I want to build is like this:
const expected = {
  foo: ["xyz", "abc"],
  bar: ["aaa"]
}
The values are transferred to the keys and pushed into the same array for duplicate keys. So far I only extracted the keys with:
const result = [...new Set(data.map(item => item.key))];  // ["foo", "bar"]
 
     
     
     
    