Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

220
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda