Scope of counter variable i in setInterval within a for loop
<p>How do I set 'i' in the function below to be incremental inside the setInterval rather than reading the final value of 'i' ?</p>

<pre><code>    window.onload= function(){
        var res = ['a','b','c']
        for(i=0;i&lt;res.length;i++){
            document.body.innerHTML += "&lt;li id='L"+i+"' style='display:none;'&gt;"+res[i]+"&lt;/li&gt;";
            setTimeout(function(){ 
                document.body.innerHTML += 'L'+i+'&lt;br/&gt;';
                document.getElementById('L'+i).style.display = 'block'
            },1000+i*50);
        }
    }
</code></pre>

<p>outputs:</p>

<pre><code>L3
L3
L3
</code></pre>
