+ 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); }
2 Respuestas
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
0
Thanks Rajeeb for it interest.
but I am getting this output:-
Index: 4, element: undefined