I would like to transform the following array
[{ 0-1s: 6, 1-2s: 2, country: "us" }, { 0-1s: 1, 1-2s: 4, country: "ja" }, { 0-1s: 3, 1-2s: 9, country: "ca" }] Into an array like this:
[{ time: "0-1s", us: 6, ja: 1, ca: 3 },{ time: "1-2s", us: 2, ja: 4, ca: 9 }] The idea is to pivot my array and make the country fields a new property and the time it took for each country a bucket so no matter how many countries, I only have 2 elements in my array (with as many countries as properties) This is just an example and I have 40+ countries. However, I haven't been able to figure out how can I achieve this new data structure in plan JavaScript.
How should I approach this?