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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:09:20+00:00 2026-05-11T09:09:20+00:00

I have a set of global counter variables in Javascript: var counter_0 = 0;

  • 0

I have a set of global counter variables in Javascript:

var counter_0 = 0; var counter_1 = 0; var counter_2 = 0; 

etc

I then have a Javascript function that accepts an ‘index’ number that maps to those global counters. Inside this function, I need to read and write to those global counters using the ‘index’ value passed to the function.

Example of how I’d like it to work, but of course doesn’t work at all:

function process(index) {     // do some processing      // if 'index' == 0, then this would be incrementing the counter_0 global variable     ++counter_+index;       if (counter_+index == 13)     {         // do other stuff     } } 

I hope what I’m trying to accomplish is clear. If not I’ll try to clarify. Thanks.

EDIT Clarification:

I’m not trying to increment the name of the counter, but rather the value the counter contains.

  • 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. 2026-05-11T09:09:21+00:00Added an answer on May 11, 2026 at 9:09 am

    Looks like an array to me, or am I missing something?

    var counters = [0,0,0];  function process(index) {    ++counters[index];        /* or ++counters[index]+index, not sure what you want to do */    if (counters[index] === 13) {        /* do stuff */     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have set a var in my code then made it global, but for
I have set an array in my config file that I use global in
I have a set of global variables and a method in a cpp file.
Imagine I have a set of global methods that aren't associated with any specific
I have set up ninject on my project in the global.asax file... protected void
Season's greetings! I have a function that prints out the contents of a char**
is there away to set global mouseReleaseEvent? what i mean is i have QMainWindow
I have global variables: point4 * mypoints; color4 * mycolors; And a block of
In my DoWork() function I register with our sip server. Then I have to
Right now, I have F5 set to start gdb in emacs for me: (global-set-key

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.