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
assign a new property (a) to json object and give it a value of another property (b), then I want to change the (b) and keep (a) does not work
const obj = {
 a: 1,
 b:2,
 c:3
} 
const first = obj.a;
obj.z = first;
obj.a = '';

when I apply obj.a = ''; I get the result

const obj = {
 a: '',
 b:2,
 c:3,
 z:'',
}

it causes obj.z to change too but I need to keep the original value of z --> 1;

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Unfortunately Js uses assign by reference in default so you need to using assign by value you can reach that by Object.assign(), Here's a link illustrate the mentioned method.

Try this:

const obj = {
  a: 1,
  b:2,
  c:3
} 
const first = obj.a;
Object.assign(obj, {z: first});
obj.a = '';
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!