I am working on chrome extension (StackEye) and as per my use case, I have to delete some objects from localStorage in a loop. Here is my code,
for (var i = 0; i < objectKeys.length; i++) {
chrome.storage.local.remove(objectKeys[i], function() {
// Do something with objectKeys[i] like remove the corresponding element from DOM
// Show notification to user that objectKeys[i] item has been removed
});
}
You can see I have used Closure
here to identify which particular object was removed and do something with it later. But the issue is
It is possible that when anonymous method (remove success handler) will be called till then value of i might have changed in the loop and it affects the action in the handler.
How do I solve this problem ?