Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

106
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda