Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use parenthesis:</p> <pre><code>var str = "foobar" + (1+i) + "other stuff"; </code></pre> <blockquote> <p>I have the same problem if I try to do the addition outside of the string and store in a variable as well, it still converts to string instead of doing addition.</p> </blockquote> <p>It should not. My guess is that you are doing something wrong there too.</p> <p><strong>Update:</strong> It seems you are converting <code>i</code> to a string somewhere in the code you did not post.</p> <p><strong>Update 2:</strong> <a href="https://developer.mozilla.org/en/JavaScript/Reference/Statements/for...in#Description" rel="nofollow">Don't use <code>for..in</code> to loop over an array</a>. Use a normal <code>for</code> loop if it is really an array:</p> <pre><code>for(var i = 0, l = imgURLArray.length; i &lt; l; i++) </code></pre> <p>But if it is an objects:</p> <p><code>for...in</code> will always set <code>i</code> as a string (as it loops over the properties of the object which are not always integers) . That means you would have to convert <code>i</code> <em>before</em> you do any addition:</p> <pre><code>... + (1 + (+i)) + ... </code></pre> <p><strong>Update 3:</strong></p> <p>You don't always have to use such an "explicit" for loop. For example, you can traverse the array in reverse order, which makes the head shorter:</p> <pre><code>for (var i = imgURLArray.length; i--; ) { str = "&lt;li photonum="+i+"&gt;" + "&lt;a&gt;"+ (1+i) + "&lt;/a&gt;" + "&lt;/li&gt;"; $("ul.selection-list").prepend(str); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload