I have a Javascript/Typescript code that looks like this:
for (let item of itemList) {
this.myService.myMethodReturningPromise(item.id).then(success => {
item.value = success;
});
}
By the time my Promise resolves, I have already exited the loop and I no longer have reference to item
.
Why is it able to correctly set the value of each item in itemList
?