I would like to know if it is possible to create a multidimensional array already setting values in it.
In php for example, it is possible for me to do:
$data['teste1']['teste2']['teste3'] = 'valor';
That automatically creates an array with the indices one inside the other. Would it be possible following the same principle to do the same thing in Javascript?
When i do
const data = [];
data['teste']['teste2']['teste3'] = 'valor'
I get the message "Cannot read property 'teste2' of undefined".
What I find strange is that for the first index ('teste') it is created, it just doesn't find/create the second index
The only way I found to solve this was by defining each array index and setting an initial value and then pushing this new array
game['goals'] = {
'0,5': {over: 0, under: 0},
'1,5': {over: 0, under: 0},
'2,5': {over: 0, under: 0},
}
game['handicap'] = {
'0,5': {over: 0, under: 0},
'1,5': {over: 0, under: 0},
'2,5': {over: 0, under: 0},
}
data.games = game