Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
How to create a multidimensional array already setting a value

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
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda