Hi I'm using reduce to create a more usable JSON structure for the following data.
data = [
{ "0": "key1", "1": "value1" },
{ "0": "key2", "1": "value2" },
{ "0": "key3", "1": "value3" },
{ "0": "key1", "1": "value4" },
];
I used reduce for this, and here is how it looks.
reduce_data = data.reduce((p, c) => {
p[c["0"]] = c["1"];
return p;
}, {});
console.log(reduce_data);
Output is as follows
{key1: "value4", key2: "value2", key3: "value3"}
If you see Im missing key1 and its value1. I understand its by design, but Im wondering if there is a way for me to get
{key1: "value1, value4", key2: "value2", key3: "value3"}
Please let me know if I'm using reduce incorrectly. Thanks!