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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:49:17+00:00 2026-05-31T23:49:17+00:00

I came across a confusing fact during coding a script. How can i find

  • 0

I came across a confusing fact during coding a script.

How can i find the variable which is equal to the value of another variable. THEN , get the value of that variable.

Here’s an example:

var result;
var 1 = "john";
var 2 = "amy";
var 3 = "micheal";

var info = "1";

When var info is set to 1 , the script will then look for variable 1 which has the value JOHN then get the value john . Then set the result’s value to “john”.

For the same thing ,

When var info is set to 2 , the script will then look for variable 2 which has the value AMY then get the value amy . Then set the result’s value to “amy”.

and so on..

My info variable’s value is not determined. it could be 1 , 2 or 3 which is set/determined by an user event.

P/S i can use if and else , but i want to know how this can be done. 🙂

So how can i 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-31T23:49:18+00:00Added an answer on May 31, 2026 at 11:49 pm

    You probably want to do something very different:

    var result;
    
    var names = {
      '1': 'john',
      '2': 'amy',
      '3': 'michael'
    };
    
    var info = "1";
    result = names[info];
    

    That will put ‘john’ into result.

    You see, this defines something called a “lookup table”, and saves it into names. Then, you can use a “key” (in your case: 1, 2, 3) to look up a value. Writing names[info] looks inside info, and gets its value, which in the above example is "1". It then looks for the key "1" inside names, and sees that the value for "1" is 'john'.

    I know this isn’t exactly what you were asking about, but I suspect it might help.

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

Sidebar

Related Questions

Came across this error today. Wondering if anyone can tell me what it means:
I recently came across this website: http://studiostyles.info , which contains a list of color
Came across the following struct which is defined in tcl.h, the C language API
Came across code recently in Wicket like so: Form<?> form = new Form<Void>(form) Can
Last night I came across the term called Jython which was kind of new
During my work with expression trees for a few days now, I came across
Came across a problem which google searches could not help me with. I have
Came across this, what is -z in the shell script if [ -z ${FILE_LIST}
I came across code written by somebody which caught some exception and tried logging
Came across something strange while migrating to my new server. I have a script

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.