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

108
Vistas
Javascript - Testing a Character against subset without RegEx

Is there a way to test for occurrence of specific characters in a more elegant way using Javascript syntax but without RegEx? Trying to avoid repetitive 'or' conditions if possible.

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

Thanks.

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

There are a couple of ways of doing this:

  1. Use an array and includes: ['+', '-', '*', '/'].includes(target)
  2. Use an object with keys your values and check for that
 const values = { '*': true, '-': true, '+': true, '/': true}
 if (values[target] === true)

But writing a long boolean condition could also work. Just wrap that in a function so you don't have to c/p code around

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