I am trying to run a code in which I loop through a function like
$.each(imageArray, function(key, value) {
setTimeout(function() {
functionName(value);
}, 4000);
});
and the function I am comparising two images through Node.js's resemble.js and its showing values like
[Log] 1--0.00 (main.js, line 69)
[Log] 9 (main.js, line 245)
[Log] 2 (main.js, line 245)
[Log] 4 (main.js, line 245)
[Log] 8 (main.js, line 245)
[Log] 6 (main.js, line 245)
[Log] 7 (main.js, line 245)
[Log] 1 (main.js, line 245)
[Log] 10 (main.js, line 245)
[Log] 3 (main.js, line 245)
[Log] 5 (main.js, line 245)
[Log] 2--34.95 (main.js, line 69)]
I know I am not doing anything wrong but the output shows otherwise.
So I am using setTimeout
because the function I am using might take time to execute.
So my question is can I force my function to loop through synchronously ?