I have a loop that calls a function thrice with different parameters using different timeout intervals:
<script type="text/javascript">
var myArray = [];
for (i=0; i<3; i++) {
myArray[i] = [];
myArray[i]['second'] = (1+i)*3000;
myArray[i]['valeur'] = i+i;
setTimeout(function() {
otherfunction(myArray[i]['valeur']);
}, myArray[i]['second']);
}
function otherfunction(data1) {
console.log(data1);
}
</script>
The script correctly calls otherfunction() but there's an error:
Uncaught TypeError: Cannot read property 'valeur' of undefined
how do I solve this problem. Looks like a problem concerning variable scope.