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

122
Views
Mutate nested deep object

I have this object

const a = {
  elementErrors: {
    errorMessages: [],
    errors: {
      project: "Issues with this Issue Type must be created in the same project as the parent."
    }
  },
  issueKey: "JP-55",
  status: 400
}

and I want to mutate it so that the nested project property includes the issueKey property at the end of the string, something like "Issues with this Issue Type must be created in the same project as the parent (JP-55)."

I know I should show that I tried and I did but I haven't managed to come with the beginning of a solution.

The final object would look like this:

const a = {
      elementErrors: {
        errorMessages: [],
        errors: {
          project: "Issues with this Issue Type must be created in the same project as the parent (JP-55)."
        }
      },
      issueKey: "JP-55",
      status: 400
    }

Many thanks

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

0

You want to compute a new property based on some other values. Just try to access and override it.

If you always have a dot at the end, you can use a mix of split() and template literals.

const a = {
  elementErrors: {
    errorMessages: [],
    errors: {
      project: "Issues with this Issue Type must be created in the same project as the parent."
    }
  },
  issueKey: "JP-55",
  status: 400
}

a.elementErrors.errors.project = `${a.elementErrors.errors.project.split('.')[0]} (${a.issueKey}).`;

console.log(a);

PS: Above code will break if there is no .

about 4 years ago · Juan Pablo Isaza Report

0

You can use the += operator to 'add' something to the end of the string.

a.elementErrors.errors.project += ` (${a.issueKey})`;

let a = {
  elementErrors: {
    errorMessages: [],
    errors: {
      project: "Issues with this Issue Type must be created in the same project as the parent."
    }
  },
  issueKey: "JP-55",
  status: 400
}

a.elementErrors.errors.project += ` (${a.issueKey})`;

console.log(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!