loading...

re: A tricky JavaScript interview question asked by Google VIEW POST

FULL DISCUSSION
 
for (var i = 0; i < arr.length; i++) {
  setTimeout(function(index, element) {
    console.log('Index: ' + index + ', element: ' + element);
  }, 3000, i, arr[i]);
}

will also produce expected output

 

Wow! I didnt know you could pass more arguments to the setTimeout function like that. Good to know, thank you!

code of conduct - report abuse