Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!