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

133
Views
Append an object without merging

I have looked around but didn't exactly find what I'm looking for: I want to append to child object values without merging.

EG:

const ADDRESS = {
  address1: {
    line1: 'blah 1'
    // ...
  },
  address2: {
    line1: 'blah 2'
    // ...
  },
  address3: {
    line1: 'blah3'
    // ...
  },
  address4: {
    line1: 'blah3'
    // ...
  }
}

If I use spread operator they get merged, I just want them appended

const addressesappended = {
  ...ADDRESS.address1,
  ...ADDRESS.address2
}

DESIRED Result:

{
  address1: {
    line1: 'blah 1'
    // ...
  },
  address2: {
    line1: 'blah 2'
    // ...
  }
}
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You could get the values only.

const
    ADDRESS = { address1: { line1: 'blah 1' }, address2: { line1: 'blah 2' }, address3: { line1: 'blah3' }, address4: { line1: 'blah3' } };
    result = Object.values(ADDRESS);

console.log(result);

about 4 years ago · Juan Pablo Isaza Report

0

You can clone the whole object using

const result = Object.assign({}, ADDRESS);

you can manually assign the child objects if matches "address"

let result = {};
for (const [key, value] of Object.entries(ADDRESS)) {
    if(key.includes("address")) result[key] = value;
}
about 4 years ago · Juan Pablo Isaza Report

0

You will need to declare the keys for the associated spread data in the target object.

const addresses = {
  address1: { line1: 'blah 1' },
  address2: { line1: 'blah 2' },
  address3: { line1: 'blah3' },
  address4: { line1: 'blah3' }
};

const addressesAppended = {
  address1: { ...addresses.address1 },
  address2: { ...addresses.address2 }
};

console.log(addressesAppended);
.as-console-wrapper { top: 0; max-height: 100% !important; }

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!