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

138
Visualizações
Using an empty string in path fails

In my node API i have some function that updates the email address Array of either a contact or a farm, its the same concept but the difference is where the array is located in farms is in Records.emails and in Contacts its in emails. So in my case I decide based on _type what the path is.

  if(result.content._type === "farm") {
      emailPath = 'Record'
      emailPathFull = 'Record.emails'

    } else {
      emailPath = ''
      emailPathFull = 'emails'
    }
    
   var e_emails = result.content[emailPath].emails;

In case the emailPath is '' which happens to be the case for Contact it cant get the data. So i am wondering if there is a way to make this work other then using

 if(result.content._type === "farm"){
     e_emails = result.content.Record.emails;}
  else {
     e_emails = result.content.emails;}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can't do it like that, and more so, you don't need too.

  1. Define a variable that will receive the value of emails.
  2. Use the conditional to disambiguate the input
  3. Copy the emails from where it resides in the input, based on type
let e_emails

if(result.content._type === "farm") {
  e_emails = result.content.Record.emails
} else {
  e_emails = result.content.emails
}
    
console.log(e_emails)
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