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

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

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