increment a var

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mickey0
    New Member
    • Jan 2008
    • 142

    increment a var

    Code:
     for (var i in data.value.items) { 
       Number = "<b><i> Number: " + (i +1) + "</i></b><br /><br />";
    }
    Hi, I have this code, but I need augmenting by "1" the result; in my output web page appear:
    01
    11
    21
    31
    41
    ......
    How to solve? thanks...
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by mickey0
    Code:
     for (var i in data.value.items) { 
       Number = "<b><i> Number: " + (i +1) + "</i></b><br /><br />";
    }
    Hi, I have this code, but I need augmenting by "1" the result; in my output web page appear:
    01
    11
    21
    31
    41
    ......
    How to solve? thanks...
    What are you trying to display? The data items numbered from 0 upwards?
    If that is the code that produced that output, then why was "Number" not printed as well?
    Perhaps if you explain further what you want to do and post more of the code you are using( in code tags).

    Comment

    • mickey0
      New Member
      • Jan 2008
      • 142

      #3
      hello,
      I want:
      1
      2
      3
      4
      and not
      01
      11
      21
      31
      41

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        hi ...

        i guess that i is a string so try:

        [CODE=javascript]for (var i in data.value.item s) {
        Number = "<b><i> Number: " + (parseInt(i, 10) + 1) + "</i></b><br /><br />";
        }[/CODE]
        kind regards

        Comment

        Working...