I have a 2d array with up to [32][32] entries. And I'd like to convert it from something like this:
[
null,
null,
null,
null,
null,
null,
[null, null, null, null, null, null, null, null, null, null, "player1"],
[null, null, null, null, null, "player2"]
]
to
{
"6": {"10":"player1"},
"7": {"5":"player2"}
}
So this would be my array:
var gameField = [];
gameField[6] = [];
gameField[6][10] = "player1";
gameField[7] = [];
gameField[7][5] = "player2";
Now I tried to use this:
var obj = {}
obj = Object.assign({},gameField);
console.log(JSON.stringify(obj));
but it only worked for the outer array, the inner arrays were not affected:
{
"6": [null, null, null, null, null, null, null, null, null, null, "player1"],
"7": [null, null, null, null, null, "player2"]
}
What would be the shortest way to do this properly?
[ {player:'player1', numberOfX:10}, {player:'player2', numberOfX:5} ].