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

239
Vistas
How to clone object with different specific values

I Want to split objects by assessment unit ids.

I have this


{ 
"name": "test",
"description": "test",
"asessment_units[]": ["2", "4", "5","8"]
}

and from this object I want four objects (because I have 4 elements in the assessment unit).

1 st object

{ 
"name": "test",
"description": "test",
"asessment_units[]": ["2"]
} 

2nd object

{ 
"name": "test",
"description": "test",
"asessment_units[]": ["4"]
} 

3rd object

{ 
"name": "test",
"description": "test",
"asessment_units[]": ["5"]
} 

4th object

{ 
"name": "test",
"description": "test",
"asessment_units[]": ["8"]
} 
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Maybe you could use Array.prototype.map and Object.assign:

const obj = {
  name: "test",
  description: "test",
  "asessment_units[]": ["2", "4", "5", "8"],
};
const splitObjs = obj["asessment_units[]"].map(unit =>
  Object.assign({}, obj, {
    "asessment_units[]": [unit],
  })
);
console.log(splitObjs);

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use Array.prototype.map() on asessment_units[] to achieve the transformation. Spread name and description keys of the object as they are common and insert respective value in an array inside the callback of map.

const obj = { 
  "name": "test",
  "description": "test",
   "asessment_units[]": ["2", "4", "5","8"]


}

 const res = obj['asessment_units[]'].map((val,index)=>{

   return {...obj, ['asessment_units[]'] : [val]}
})
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