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

140
Views
Use object assign to make a copy of object without object reference

I have an array of objects which I want to make a copy of so I can modify later and not affect the original.

const myArray = [
    {
      id: 111,
      name: 'Nikki',
    },
    {
      id: 222,
      name: 'Jimbo',
    },
    {
      id: 333,
      name: 'Frank',
    },
];

To make the copy Ive used this below which works but I still feels a bit hacky

const copyOfMyArray = JSON.parse(JSON.stringify(myArray));

I have seen Object.assign({}, obj) being suggested for this but when I try to use it as below and transform it later myArray is still affected.

const copyOfMyArray = Object.assign([{}], myArray)

Is there any way to use Object.assign so it removes the original object reference?

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