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

137
Views
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 answers
Answer question

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 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!