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

167
Views
Cómo hacer un objeto anidado a partir de una matriz

dada una matriz como ['a', 'b', 'c']

¿Cómo puedo obtener un objeto como

 { current: 'a', next : { current: 'b', next: { current: 'c' } } }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puedes hacer una función recursiva para esto:

 const data = ['a', 'b', 'c']; function createObj([current, ...rest]) { const result = { current }; if (rest.length) result.next = createObj(rest); return result; } console.log(createObj(data));

El [current, ...rest] es un único argumento de matriz desestructurado .

about 4 years ago · Juan Pablo Isaza Report

0

Puede usar Array.reduceRight() para crear el objeto:

 const arr = ['a', 'b', 'c'] const obj = arr.reduceRight((acc, o) => ({ current: o, ...acc && { next: acc } }), null) console.log(obj)

about 4 years ago · Juan Pablo Isaza Report
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!