settimeout in for loop is not working
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/5226285/settimeout-in-a-for-loop-and-pass-i-as-value">setTimeout in a for-loop and pass i as value</a>  </p>
</blockquote>



<p>i am trying generate dynamic array  and using this array as loop .. but in loop settime out is not working or function is not working.
Here is my code </p>

<pre><code>jQuery(document).ready(function () {
    temp = new Array();
    generateArray(temp);

    function generateArray(temp) {
        if (temp.length &lt; 10) {
            res = randomXToY(1, 10, 0);
            for (var k = 0; k &lt; temp.length; k++) {
                if (temp[k] == res) {
                    var test = 1;
                }
            }
            if (test != 1) {
                temp.push(res);
                //abc(temp);
            }
            generateArray(temp);
        } else {
            for (var z = 0; z &lt; 10; z++) {
                tnest(temp[z]);
                setTimeout(function () {
                    removeClassImg(temp[z])
                }, 3000);
            }
            temp = new Array();
            generateArray(temp);
        }
    }

    function removeClassImg(result1) {
        alert(result1);
        $('#img' + result1).fadeTo(12000, 0.1);
        return true;
    }

    function tnest(result) {
        alert(result);
        $('#img' + result).fadeTo(12000, 1);
        return true;
    }

    function randomXToY(minVal, maxVal, floatVal) {
        var randVal = minVal + (Math.random() * (maxVal - minVal));
        return typeof floatVal == 'undefined' ? Math.round(randVal) : randVal.toFixed(floatVal);
    }
});
</code></pre>

<p>alert in function removeClassImg  is not working .. i am using settimeout in for loop this is not working fine.</p>
