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

99
Views
New object created with the help of spread operator behaving like it is a deep copy, even though it has a nested object

Image of the code

So i created a new object from one object using spread operator and used another object to modify is property values.

But i am not sure, why it behaves as it is a deep copy instead of a shallow copy.

Cause as much as i remember, the way that i have done it, it should create shallow copy only in javascript (Node 12 or 14 version).

 const modifier = {
    policyName: "Asa1",
    test: {
        a: "As1",
        bc : [
            {
                a: 1
            }
        ]
    }
}


 const memberDetails = {
    policyName: 'policyName',
     test: {
        a: "As",
        bc : [
            {
                a: 0
            }
        ]
    }
};

const generatedMemberDetails = {...memberDetails, ...modifier};
generatedMemberDetails.test.a = "newAs";
generatedMemberDetails.test.bc[0].a = "new0";
console.log(JSON.stringify(memberDetails) );
console.log(JSON.stringify(generatedMemberDetails));

Output: 
{"policyName":"policyName","test":{"a":"As","bc":[{"a":0}]}}
{"policyName":"Asa1","test":{"a":"newAs","bc":[{"a":"new0"}]}}
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!