ChristoK ChristoK -4 years ago 39
Javascript Question

why is index getting incremented like this? javascript

First console log: 0, as expected.
Second console log: 1.
Why index got incremented before the end of loop?

for (var i = 0; i < this.offlineTimeSlots.length; i++) {

console.log(i);'http://localhost:63203/api', JSON.stringify(this.offlineTimeSlots[i]), { headers: headers })
.map(res => res.json())
.subscribe(data => {


}, (err) => {

Answer Source is the asynchronous function so it will executed separately

For loop will continue its execution and it's not depends on the

Concept is called event-loop : Please read this

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download