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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:30:44+00:00 2026-05-31T20:30:44+00:00

The title explains it pretty well, but I’m trying to build a ‘for loop’

  • 0

The title explains it pretty well, but I’m trying to build a ‘for loop’ that matches a variable (in this case, one garnered by an HTML5 form) to a value in a cell in a 2-column database. Then I want to ‘console.log’ the value in the adjacent (next column over) cell.

Looking for coding help and any suggestions for what type of database would work best with this type of arrangement.

var myDB = {AA:100, BB:50, CC:75, DD:66, EE:40};
function DB(value) {
    return myDB[value];
}
console.log(DB('AA'));
  • 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-31T20:30:45+00:00Added an answer on May 31, 2026 at 8:30 pm

    It seems to be the best approach for this would be to have a data structure like this:

    var myDB = {
        'key1' : 'value1'
    }
    

    This would remove the need for a “for loop” as you were planning to use which is incredibly inefficient and would enable you to use a simple index check like this:

    function getValue( index ) {
        if( typeof myDB[index] == 'undefined' ) return false;
        return myDB[index];
    }
    

    If you need to be able to search on either index, then you’ll need to make a slightly more complex database layout (I’m assuming your “database” is actually just javascript data since you wanted to console.log the data.

    If you’re looking to do this in a server side database and return the data, you’ll need AJAX functionality and server side APIs to post those ajax requests to and return your data in JSON. Which is slightly more complicated than what I just suggested above.

    Update:

    If you wanted to “search” the database values and find the matching key, you would probably have to either run a for loop on the myDB object, or build your database a little differently by having a separate object for each of the keys and one for the data. Something like this:

    var myDB = {
        'key1' : {
            'value1':0,
            'value2':1
         },
        'key2' : {
            'value1':0,
            'value2':1
        },
        'data' : {
            0:'data_for_record_1',
            1:'data_for_record_2'
        }
    }
    

    Now you can “search” on either of the index columns and get the ID of the data row that corresponds to that matched column. This data structure is very similar to how indexes are used in most databases like MySQL and others. So your “search” function would likely look something like this:

    function searchDB( index , value ) {
        if( typeof myDB[index][value] == 'undefined' ) return false;
        if( typeof myDB.data[myDB[index][value]] == 'undefined' ) return false;
        return myDB.data[myDB[index][value]];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the title pretty much explains it. Please note that this is a WebKit-specific issue
Well, title explains all. I'm trying to get rid of the highlight that comes
I'm not sure the title explains it well enough, but was trying to keep
Title pretty much explains it all, its the last thing I'm trying to work
I think the title explains my question pretty well, I'm currently working on a
Well the question title explains the question :D but here is an example none
The title pretty much explains it. I'm having an odd situation where views that
Well the title explains pretty much everything. I want to use something like p
The title pretty much explains it all, I have a Member object that references
The title pretty much explains it all, I have a Member object that references

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.