我在Javascript中有一组全局计数器变量:
var counter_0 = 0;
var counter_1 = 0;
var counter_2 = 0;
Run Code Online (Sandbox Code Playgroud)
等等
然后我有一个Javascript函数接受一个映射到那些全局计数器的'索引'号.在这个函数中,我需要使用传递给函数的'index'值来读取和写入这些全局计数器.
我希望它如何工作的示例,但当然根本不起作用:
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
}
}
Run Code Online (Sandbox Code Playgroud)
我希望我想要完成的事情是清楚的.如果不是,我会尽力澄清.谢谢.
编辑澄清:
我不是试图增加计数器的名称,而是增加计数器包含的值.