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

  • Home
  • SEARCH
  • 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

Season's greetings! I have a function that prints out the contents of a char**
I have multiple threads (C# application running on IIS) running that all need to
I have a question about setting the style attributes for a data cell in
I have a bunch of large HTML files and I want to run a
I am writing a large C program for embedded use. Every module in this
Is there a way to get the trace table for a Python program? Or
I want to connect and execute one (or sometimes several) SQL statements, and NOT
I need a timer tick with 1ms resolution under linux. It is used to
I am trying to import CSV file to SQL server database, with no success.

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.