Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

238
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda