+ 1

What will the following code output?

const arr = [10, 12, 15, 21]; for (var i = 0; i < arr.length; i++) { setTimeout(function() { console.log('Index: ' + i + ', element: ' + arr[i]); }, 3000); }

18th May 2018, 2:12 AM
Shrinath Dhatrak
Shrinath Dhatrak - avatar
2 Réponses
0
ans:- index: 0 , element: 10 // 3sec delay index: 1 , element: 12// 3sec delay index: 2 , element: 15// 3sec delay index: 3 , element: 21 // 3sec delay
18th May 2018, 2:47 AM
Rajeeb
0
Thanks Rajeeb for it interest. but I am getting this output:- Index: 4, element: undefined
18th May 2018, 3:34 AM
Shrinath Dhatrak
Shrinath Dhatrak - avatar