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

140
Views
Js cómo configurar un elemento en un índice anidado en una matriz vacía

Tengo esta matriz que debe llenarse con objetos. Cada objeto tiene un slug con 4 secciones divididas por "-" (por ejemplo: test-dx-ef-1) y dependiendo de eso tengo que colocarlos en una matriz en un índice específico nombrado con la sección de slug.

Intenté hacer un bucle de todas las entradas y establecer directamente el objeto de esta manera:

 var data = [] objects.forEach((obj) => { var slug = obj.slug.split('-') data[slug[0]][slug[1]][slug[2]][slug[3]] = obj }

Pero no funcionó, ya que aparentemente, incluso si se pueden crear data[slug[0] data[slug[0]] , data[slug[0]][slug[1]] resulta indefinido y se genera un error.

¿Hay alguna manera en que pueda lograr esto?

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!