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

224
Views
Find an element and add character to the string

I have an object (obj) containing an array (create), I would like to access the create.field and modify 'OWNER' to 'OWNER_ID'. I have other data in the create array so I do not wish to erase it.

 const obj = {
 pro: 0,
 gr: 0,
 create: [
{
  field: "OWNER",
  value: 12345
}
]
};

this is what I have now :

const owner = obj.create.find((ele) => ele.field === 'OWNER'.join('_ID');
console.log('owner', owner);
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

if I understand correctly you can do this

const newObject = {
    ...obj,
     create: obj.create.map(({ field, value }) => ({ field: field === "OWNER" ? `${field}_ID` : field, value })),
}
about 4 years ago · Juan Pablo Isaza Report

0

You need to find element first, then you need to assign the owner.field property to its value plus the _ID

 const obj = {
 pro: 0,
 gr: 0,
 create: [
{
  field: "OWNER",
  value: 12345
}
]
};

const owner = obj.create.find((ele) => ele.field === 'OWNER');
owner.field = owner.field +'_ID'
console.log('owner', owner);
console.log('obj', obj);

about 4 years ago · Juan Pablo Isaza Report

0

Try:

const obj = {
   pro: 0,
   gr: 0,
   create: [
      {
        field: "OWNER",
        value: 12345
      }
   ]
};

let owner = obj.create.find(x => x.field == "OWNER");
if(owner) {
  owner.field = "OWNER_ID";
}
console.log(obj);
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!