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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:33:25+00:00 2026-06-01T14:33:25+00:00

I am new to javascript so sorry I don’t know very much. I have

  • 0

I am new to javascript so sorry I don’t know very much. I have the following and I would like to make it simpler. Any suggestion would be appreciated.

if (entity == "house") {
    primaryKey = store.getItem('accountID') + "02" + "00";
    table = "Content";
}
if (entity == "street") {
    primaryKey = store.getItem('accountID') + "0000";
    table = "Content";
}
if (entity == "city") {
    var primaryKey = store.getItem('categoryID');
    table = "Reference";
}
if (entity == "location") {
    primaryKey = "0001" + store.getItem('examID');
    table = "Content";
}
  • 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-01T14:33:27+00:00Added an answer on June 1, 2026 at 2:33 pm

    You could do it with a table driven approach and no repeated code (DRY) like this:

    var lookupInfo = {
        house: {id: "accountID", prefix, "", suffix: "0200", table: "Content"},
        street: {id: "accountID", prefix: "", suffix: "0000", table: "Content"},
        city: {id: "categoryID", prefix: "", suffix: "", table: "Reference"},
        location: {id: "examID", prefix: "0001", suffix: "", table: "Content"}
    };
    
    var primaryKey, data = lookupInfo[entity];
    if (data) {
        primaryKey = data.prefix + store.getItem(data.id) + data.suffix;
        table = data.table;
    }
    

    Besides minimizing the code and not repeating any code, it’s also easy to add more options to the table without writing any additional code.


    Or, the data table can be made a little more compact, though not quite as elegant (from a pure programming point of view because of the hard coded constants) this way:

    var lookupInfo = {
        house: ["accountID", "", "0200", "Content"],
        street: ["accountID", "", "0000", "Content"],
        city: ["categoryID", "", "", "Reference"],
        location: ["examID", "0001", "", "Content"]
    };
    
    var primaryKey, data = lookupInfo[entity];
    if (data) {
        primaryKey = data[1] + store.getItem(data[0]) + data[2];
        table = data[3];
    }
    

    Either way, you get the idea of using a lookup table for the entity and then a table driven approach for the different values for each entity.

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

Sidebar

Related Questions

I am new with javascript still, but I would like to know how to
I'm absolutely new to JavaScript and would like to modify a textarea of a
I am new to javascript in general and pretty much have no idea what
I'm new to JavaScript and programming in general (although I know some people don't
I don't have too much experience with JavaScript and Google Maps Api. What I
I am kind of very new to javascript world. I have a doubt. How
I'm new at javascript and while there are many more complex solutions, I don't
I've been using both in javascript ... really don't know the difference. Googling always
Sorry, new to Firebug. I really find being able to run javascript in the
Sorry, still reasonably new to Javascript here, so hope this question isn't too embarrassingly

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.