每次调用“for {}”语句时添加数字

时间:2012-10-13 22:03:46

标签: javascript math

我在这样的函数中有一个for语句:

for(i=0;i<=nc;i++){
var nd = //how many times this for statement has run+1
//if the for statement runs for the first time nd would be 1, second time nd would be 2, the for statement will run a total of "nc" times
this.id=nd }

我将如何实现这一目标?

3 个答案:

答案 0 :(得分:1)

你是说那个意思吗?

for(i=0;i<=nc;i++){
   var nd = i+1;
   this.id=nd;
}

答案 1 :(得分:1)

我不知道你想要用什么来实现

for(i=0;i<=nc;i++)
{
   this.id = i+1; 
}

答案 2 :(得分:0)

在函数

之外声明nd
var nd = 0;
function...
    nd++;
    this.id = nd;