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

237
Views
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 answers
Answer question

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 Report

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 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!