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

107
Visualizações
Select an object with particular condition

Basically, I am selecting part of the object (values) and I want to inject CreateValue to this object, but with certain condition. I want to check if the field starts with a 'FLD_STR_' and if this field contain an object. I have multiple field 'fld_str_' hence the reason I want to only select the one that contains an object and not a string. I do not think I need to loop in this case. Just add a condition

const values = {
  ID: 748817,
  CODE: "OFFLINE-003",
  FLD_STR_101: {
    field: "FLD_STR_101",
    name: "doc.pdf",
    value: 'base64',
    type: "application/pdf"
  },
  FLD_STR_102: "coucou",
  Table: 109414,
  OWNER: "MJACQUIER",

}
const ele = ()=>{
  if (values.startsWith('FLD_STR_') &&
  typeof values.startsWith('FLD_STR_') === 'object') {
  values.createFileValue = values.startsWith('FLD_STR_');
  
  }
}
console.log(ele())

this is the output :

const values = {
  ID: 748817,
  CODE: "OFFLINE-003",
  FLD_STR_101: {
    field: "FLD_STR_101",
    name: "doc.pdf",
    value: 'base64',
    type: "application/pdf"
  },
  FLD_STR_102: "coucou",
  Table: 109414,
  OWNER: "MJACQUIER",
"createFileValue": {
    field: "FLD_STR_101",
    name: "doc.pdf",
    value: 'base64',
    type: "application/pdf"
  }

}
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

what does values.startsWith('FLD_STR_') ? values is object not a string, try this

const keys = Object.keys(values);
keys.forEach(key => {
  if(key.startsWith('FLD_STR_') && typeof values[key] === 'object'){
    values.createFileValue = values[key];
  }
})
about 4 years ago · Santiago Gelvez 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