I have an array of JavaScript objects, which looks something like this.
[ { name: "A", tp1: 10, tp2: 20, ... tp31: 30 },
{ name: "B", tp1: 11, tp2: 21, ... tp31: 31 },
{ name: "C", tp1: 12, tp2: 22, ... tp31: 32 },
{ name: "D", tp1: 13, tp2: 23, ... tp31: 33 } ]
I want to rearrange the data slightly differently. At the moment, you could say that the "key" (so to speak) is the name. I want the object to be grouped using a different attribute, say tp1
, and have the values of each "name" in the object put in as attributes of their own.
My explanation may be terrible, but basically, I want to transform it into the following format:
[ { x: "tp1" , A: 10, B: 11, C: 12, D: 13 },
{ x: "tp2" , A: 20, B: 21, C: 22, D: 23 },
...
{ x: "tp31", A: 30, B: 31, C: 32, D: 33 } ]
I genuinely have no idea where to start with this.
Thanks in advance.