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

87
Views
Cambiar índice de objetos

¿Hay alguna forma de cambiar el índice dinámicamente? o reconstruir este objeto donde el 1 será el Id de cualquier objeto que se pase a la función? Espero que esto tenga sentido.

 export const createTree = (parentObj) => { //keep in memory reference for later const flatlist = { 1: parentObj }; <---- change the 1 based on parent.Id ... }

Mi intento pensando que sería fácil como:

 const flatlist = { parentObj.Id: parentObj };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Utilice nombres de propiedades calculadas para crear una clave a partir de una expresión:

 const createTree = (parentObj) => { const flatlist = { [parentObj.id]: parentObj }; return flatlist; } console.log(createTree({ id: 1 }));

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!