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 8860961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:23:01+00:00 2026-06-14T15:23:01+00:00

I have seen posts like Declaring Multiple Variables in JavaScript that focus on unique

  • 0

I have seen posts like Declaring Multiple Variables in JavaScript that focus on unique variables (and lots of them), but I am looking at lots of non-unique variables, for example I want to do a much larger version of this…

            var rep;
            var state_def, state_MA, state_WY, state_TN = 'joeblow';
            var state_AZ, state_TX = 'moefoe';
            var state_MT, state_OR = 'growmo';
            var state_OK, state_LA = 'billyjoe';
            var state_WA, state_NM, state_MS = 'messytess';
            var state_VA, state_NY = 'slickrick';
            var state_CA = 'icecube';

            //or
            var state_def = state_MA = state_WY = state_TN = 'joeblow';

Just to understand, I am using a switch like so…

switch (capitalise(data.regionName)) {
                case 'Arizona': rep = state_AZ; break;
                case 'Texas': rep = state_TX; break;
                case 'Montana': rep = state_MT; break;
                case 'Oregon': rep = state_OR; break;
                case 'New Mexico': rep = state_NM; break;
                case 'Mississippi': rep = state_MS; break;
                case 'Oklahoma': rep = state_OK; break;
                case 'Louisiana': rep = state_LA; break;
                case 'Washington': rep = state_WA; break;
                case 'Massachusetts': rep = state_MA; break;
                case 'Wyoming': rep = state_WY; break;
                case 'Tennessee': rep = state_TN; break;
                case 'Virginia': rep = state_VA; break;
                case 'Illinois': rep = state_IL; break;
                case 'Nevada': rep = state_NV; break;
                default: rep = state_def; break;
            };

This will have several thousand zipcodes as well, so a secondary switch for this. That is why declaring the state (or zip) variable / user association as short as possible is needed. But I also do not want to fall into any pitfalls I might be unaware of. This works right now with the exception of the default: rep = state_def; break; returning as undefined. Also, does not work in IE8.

  • 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-06-14T15:23:02+00:00Added an answer on June 14, 2026 at 3:23 pm

    I suggest replacing your switch with a mapping:

    var reps = {
        'Arizona': state_AZ,
        'Texas': state_TX,
        // etc.
    };
    
    // then you can do this:
    var rep = reps[capitalize(data.regionName)];
    

    Later, you could even download that mapping (including the values) as a JSON object or something from a server or other data source.

    Notice also, that most of your state_* variables are undefined. I don’t know if this is what you intended. If you only have data for some states, it might be better to build the data structure directly:

    var reps = {
        'Arizona': undefined, // or just omit from mapping
        'Texas': 'moefoe',
        // etc.
    };
    

    and dispense with all the state_* variables.

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

Sidebar

Related Questions

I have seen several other posts with similar questions but nothing exactly like what
I have seen several posts on the subject, but seems like there is little
I have seen posts all over the internet that talk about how to fix
I have seen many posts on this subject, but none have been answered, and
i have seen similar posts here but i have had no luck solving my
I have seen several posts similar to this but none with a strait forward
First of all, apologize because I have seen some posts about this, but I
I have seen a few posts regarding this issue but not one specific to
I have seen the other posts but I am still having trouble. Below is
I've seen a few similar posts and have tried out the answers given, but

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.