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

85
Vistas
Change Object Index

Is there way to change the index dynamically? or rebuild this object to where the 1 will be the Id of what ever object get passed into the function? Hope this makes sense.

export const createTree = (parentObj) => {

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

...

}

My attempt thinking it would be easy as:

const flatlist = { parentObj.Id: parentObj };

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Use computed property names to create a key from an expression:

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

  return flatlist;
}

console.log(createTree({ id: 1 }));

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