I have this json, which I want to convert to an array.
{
"match1": {
"team1": "2",
"team2": "0"
},
"match2": {
"team1": "3",
"team2": "1"
}
}
so far after searching and looking for simillar questions, I have come up with this
var data = {
"match1": {
"team1": "2",
"team2": "0"
},
"match2": {
"team1": "3",
"team2": "1"
}
}
const array = Object.values(data.match1).map((key) => [key, data[key]]);
console.log(array);
// outputs
//[2, , 0, ]
It looks fine but it needs me to write for each 'match' property and I need a way to output them together as the match property can be many e.g match3, match4 e.t.c. also not sure why the double comma?
so the expected output I want is
[[2,0], [3,1]];
how to do it?