Click here to Skip to main content
15,896,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
for(var i=0;i<Data.length;i++) {

           s += "<td>" + i + 1 + "</td>";

       }


The above code printing like this

01
11
21

it is doing concatenation

but I want it

1
2
3

Pls dont use extra variable to accomplish this task

Thanks
Posted
Updated 18-Jan-12 17:57pm
v3

Hi,

Use like this,

C#
for(int i=0;i<data.length;i++)
{ 
   
   s += "<td>" + (i + 1).ToString() + "</td>";
          
}
 
Share this answer
 
v3
Comments
Gowri Shankar Rao 18-Jan-12 23:59pm    
Solved. Thanks
Use this code.
The number variable is taken out and then appended with the string.

JavaScript
for(var i=0;i<data.length;i++)>
           var number = i+1;
           s += "<td>" + number + "</td>";

       }
 
Share this answer
 
v2
Comments
Gowri Shankar Rao 18-Jan-12 23:56pm    
I don't want to use extra variable to accomplish this task. any other way ....
Abey Thomas 19-Jan-12 0:01am    
Then you will have to use (i+1).toString(). Is this an interview question?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900