Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

139
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda