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

215
Views
Si la condición no funciona para la comparación de cadenas en JS

Tengo una condición if-else en js como se muestra a continuación y espero que la condición else se ejecute para la lógica a continuación, porque la ID de destino está en else if , pero siempre entra en la condición if . probado con == y === también.

¿Qué me estoy perdiendo? Nota: La lógica debe ser compatible con ie11

 // destinationId is generated dynamically but i have assigned it to a variable for reference Code 1 var fromId = "createNotification"; var destinationId ="detailedDescription"; if ((fromId == "createNotification") && (destinationId == "carNumber" || "setNumber")) { //logic to execute } else if ((fromId == "createNotification") && (destinationId == "faultRepBy" || "detailedDescription")) { //logic to execute }
 code 2 if ((["createNotification"].indexOf(fromId) > -1) && (["carNumber" || "setNumber"].indexOf(destinationId) > -1)) { //logic to execute } else if ((["createNotification"].indexOf(fromId) > -1) && (["faultRepBy" || "detailedDescription"].indexOf(destinationId) > -1)) { //logic to execute }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Cambie su condición de la siguiente manera:

 if ((fromId == "createNotification") && (destinationId == "carNumber" || destinationId == "setNumber")) { console.log("in if") } else if ((fromId == "createNotification") && (destinationId == "faultRepBy" || destinationId == "detailedDescription")) { console.log("in else if") }
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!