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

122
Views
Javascript: prueba de un personaje contra un subconjunto sin RegEx

¿Hay alguna manera de probar la aparición de caracteres específicos de una manera más elegante usando la sintaxis de Javascript pero sin RegEx? Intentar evitar las condiciones "o" repetitivas si es posible.

 if (target == "+" || target == "-" || target == "*" || target == "/") { alert("hit a function"); }

Gracias.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Hay un par de maneras de hacer esto:

  1. Usa una matriz e includes : ['+', '-', '*', '/'].includes(target)
  2. Use un objeto con claves de sus valores y verifique eso
 const values = { '*': true, '-': true, '+': true, '/': true} if (values[target] === true)

Pero escribir una condición booleana larga también podría funcionar. Solo envuélvelo en una función para que no tengas que hacer c/p alrededor del código.

about 4 years ago · Santiago Gelvez 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!