When running this code snippet, the first console log correctly shows 0. However, the second console log displays 1. Why is the index being incremented before the loop has ended?
for (var i = 0; i < this.offlineTimeSlots.length; i++) {
console.log(i);
this.http.post('http://localhost:63203/api', JSON.stringify(this.offlineTimeSlots[i]), { headers: headers })
.map(res => res.json())
.subscribe(data => {
console.log(i);
resolve(data);
}, (err) => {
reject(err);
});
}