Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6821903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:35:59+00:00 2026-05-26T21:35:59+00:00

Does JavaScript have a convenient way to test if a variable matches one of

  • 0

Does JavaScript have a convenient way to test if a variable matches one of many values?

This is my code,

function Start()
{
    if(number==(0||3||6||8||9||11||13||14||15||18||19||22||23||25||27||28||31||34||43||46||47||49||54||58||59||62||63||68||71||74||75))
    {
        FirstFunction();
    }
    if(number==(1||4||5||7||12||16||17||20||21||26||29||32||33||42||45||48||50||51||53||55||56||57||60||61||64||65||67||69||70||73||76))
    {
        SecondFunction();
    }
}

as you can see, I tried to use the “or” operator to check if number equals ANY of the listed. this, unfortunately, did not work. I know I can just code:

if(number==0||number==3||number==6....)

I think there should be an alternative to that, is there?

Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:35:59+00:00Added an answer on May 26, 2026 at 9:35 pm

    You should insert all your elements in an array and use arr.indexOf(element)

    It will return -1 if the element doesn’t exist which you can use for your if logic

    This is better than having lot of if statements

    var x = new Array(1,7,15,18);
    
    if ( x.indexOf(31) != -1 )
    {
      // Add your logic here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following JavaScript code: Link In which the function makewindows does not
I have a javascript that does this (http is your XMLHttpRequest object) var r
We have a JavaScript function named move which does just windows.location.href = any given
Does JavaScript have a way of truncating HTML text without all the headaches of
Does Javascript supports Sets(list with unique objects only) ? I have found this link
Does JavaScript have a built-in function like PHP's addslashes (or addcslashes ) function to
Question: Does JavaScript have an equivalent to PHPs output buffering (start, get_clean) or <<<
Does jquery/javascript have any event model that you can attach to your objects? Basically
Does Javascript or jQuery have sometime like the in statement in Python? a in
It looks like JavaScript does not have access to authentication cookies ('ASP.NET_SessionId', '.ASPXFORMSAUTH') in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.