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

  • SEARCH
  • Home
  • 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 6880541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:59:14+00:00 2026-05-27T04:59:14+00:00

wondering if I can make my javascript more efficient. I have a var JSP

  • 0

wondering if I can make my javascript more efficient.
I have a var JSP = “the jsp’s name”

And I have statements in a javascript validation file:

if(( JSP == "test.html" ) || ( JSP == "test1.html") || ( JSP == "test2.html" )) then blah blah blah.

Is there a more efficient way to do this?

  • 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-27T04:59:15+00:00Added an answer on May 27, 2026 at 4:59 am

    If you know that JSP contains a string, it’s slightly more efficient to use === rather than ==. Also note that you don’t need all those parens:

    if (JSP === "test.html" || JSP === "test1.html" || JSP === "test2.html") {
        // do something
    }
    

    You could also use a regular expression:

    if (/^test[12]?\.html$/.test(JSP)) {
        // do something
    }
    

    …but it depends what you mean by “efficient.” The series of === will be very efficient at runtime.

    Separately, you could use a switch:

    switch (JSP) {
        case "test.html":
        case "test1.html":
        case "test2.html":
            // Do it
            break;
    }
    

    …but I wouldn’t call it more efficient.

    I definitely would not put the options in an array, because searching through the array will not be efficient. But you can use a map:

    var pages = {
        "test.html":  true,
        "test1.html": true,
        "test2.html": true
    };
    

    …and then this test:

    if (pages[JSP] === true) {
        // do something
    }
    

    …which results in a fairly efficient property lookup. That’s only reasonable if you create the object once and reuse it.

    (You might have people say “Or just use if (pages[JSP]) { ... }. But that fails if JSP happens to contain “toString” or “valueOf” or any of several other inherited properties blank objects get from Object.prototype. It’s fine if you’re certain it won’t have any of those values, though.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering how I can make a script load powerpoint file, advance slides
I am wondering whether you can make a button, function like a HTML Radio
Just wondering how I can make my app open automatically at login, but make
I was wondering how does Nike website make the change you can see when
I was wondering how can I list the user tables name with its primary
I'm wondering how can I put a header into my PDF file, cause I've
I have a form on my site where users can make new accounts. The
Is there a decent browser-based javascript self-editor? It is obvious one can make a
I am wondering how do I disable javascript when using selenium so I can
I was wondering, if in C# under Visual Studio i can make xml comments,

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.