I need to combine two Chrome APIs in loop and after the loop is finished, save array to storage.
This is what I have
chrome.downloads.search({}, function (DownloadItem) {
for (var i=0; i<DownloadItem.length; i++) {
var itemID = DownloadItem[i].id;
chrome.downloads.getFileIcon(itemID, function(iconURL) {
DL_icons[itemID] = iconURL;
});
}
console.log(DL_icons);
});
result of search
is DownloadItem
array of objects. I need to loop through it, get ID's, and for every ID I need to pass it into call of chrome.downloads.getFileIcon
.
Result of that getFileIcon
method is iconURL
which I need to push into new array on ID index (I could store it into new object with according ID and then push it into an array, doesn't matter in this case).
After everything is done, I need to store it to local storage (or console.log...).
As it is now, I'm getting the same ID and iconURL for every array element.
Basically, I need to make a proper closure of inner API, and just can't make it right. Can someone pls help with it?