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

108
Views
Object.assign() changes values of object even if object if frozen

I wanted to write some code that flattens the values of an object. But I do not understand why the following code snipped changes the value of the original data !!!

let data = {'row1' : {'a11':10, 'a12':11},
            'row2' : {'a21':23, 'a22':11}}

let flat = Object.assign(...Object.values(data))

console.log('flat : ',flat)
console.log('data : ',data)

will result in

flat :  { a11: 10, a12: 11, a21: 23, a22: 11 }
data :  {
  row1: { a11: 10, a12: 11, a21: 23, a22: 11 },   <--- WHY!!!!!!!!!!!
  row2: { a21: 23, a22: 11 }
}

This even happenes if I freeze data,

let data = {'row1' : {'a11':10, 'a12':11},
            'row2' : {'a21':23, 'a22':11}}

data = Object.freeze(data)

let flat = Object.assign(...Object.values(data))

console.log('flat : ',flat)
console.log('data : ',data)

which also results in

flat :  { a11: 10, a12: 11, a21: 23, a22: 11 }
data :  {
  row1: { a11: 10, a12: 11, a21: 23, a22: 11 },   <--- WHY!!!!!!!!!!!
  row2: { a21: 23, a22: 11 }
}

What is going on?

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!