I have the following array with one object:
[{
"0key1": "a33",
"0key2": "Aab",
"0key3": "i",
"1key1": "e78",
"1key2": "Vib",
"1key3": "j",
"2key1": "c99",
"2key2": "Aig",
"2key3": "k"
}]
I would like to split it into three "key": "value" per row as shown below:
[
{"0key1":"a33","0key2":"Aab","0key3":"i"},
{"1key1":"e78","1key2":"Vib","1key3":"j"},
{"2key1":"c99","2key2":"Aig","2key3":"k"}
]
Please help me achieve that.
4
Answers
This snippet works for your example, but you will want to add some bounds checking if needed.
Here’s a potential approach:
I would use reduce and a nullish coalescing assigment
Short and simple. Easy to understand and gets the job done.