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

246
Views
Cómo clonar objetos con diferentes valores específicos

Quiero dividir objetos por ID de unidad de evaluación.

tengo esto

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

y de este objeto quiero cuatro objetos (porque tengo 4 elementos en la unidad de evaluación).

1er objeto

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

2do objeto

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

3er objeto

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

4to objeto

 { "name": "test", "description": "test", "asessment_units[]": ["8"] }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Tal vez podrías usar Array.prototype. map y 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 Report

0

Puede usar Array.prototype.map() en asessment_units[] para lograr la transformación. Distribuya el name y las claves de description del objeto, ya que son comunes e inserte el valor respectivo en una matriz dentro de la devolución de llamada del 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 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!