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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:42:35+00:00 2026-05-23T07:42:35+00:00

I have a variable with a value, let’s say var myVarMAX = 5; In

  • 0

I have a variable with a value, let’s say

var myVarMAX = 5;

In HTML I have an element with id="myVar".

I combine the id with the string MAX (creating a string myVarMAX). My question is how can I use this string to access a variable with the same name?

  • 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-23T07:42:36+00:00Added an answer on May 23, 2026 at 7:42 am

    You COULD use eval, but if you have the var in the window scope, this is better

    var myVarMAX = 5;
    var id="MAX"; // likely not in a var
    
    alert(window["myVar"+id]); // alerts 5
    

    However Don’t pollute the global scope!

    A better solution is something like what is suggested in the link I posted

    var myVars = {
      "myVarMin":1,
      "myVarMax":5,
      "otherVarXX":"fred"
    } // notice no comma after the last var
    

    then you have

    alert(myVars[“myVar”+id]);

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

Sidebar

Related Questions

Let's say I have: var url="http://www.google.html"; how do I put the URL variable value
So let's say I have variable like this one: $q = DB::select('id')->from('reports')->where('field', '=', 'value');;
I want to dynamically access value of variable, let's say I have this array:
Let's say I have this HTML: <select id='list'> <option value='1'>First</option> <option value='2'>Second</option> <option value='3'>Third
Let's say I have a variable called URL and it's assigned a value of
I have a variable of type Hashmap <String,Integer >. In this, the Integer value
I have string value and Type of some variable (For example int and 32
Let's say we have the following mega-simple Python script: print Initializing.... a=10 print Variable
Let's say I have a function which is being passed a string which originally
So, let's say I have this code (VB.Net): Sub Main() dim xxx as string

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.