Sync array from chrome.storage.local ajax

Viewed 18

I try to store in chrome.storage.local an array of objects but seems that value is overwritted.

The code is below:

for(let i=0; i<profileContainers.length; i++)
{
  let key = profileContainers[i].key;
  chrome.storage.local.get('Objects', result =>
  { 
      if(!result["Objects"][key])
      {    

                                    var settings = {
                                        "url": "http://localhost:48593/api/Link/GetByUrl",
                                        "method": "POST",
                                        "timeout": 0,
                                        "headers": {
                                        "Content-Type": "application/json"
                                        },
                                        "data": JSON.stringify({
                                        "Headline":headLine
                                        }),
                                       };


                             $.ajax(settings).done(function (response) {
                                        chrome.storage.local.get('Objects', r=>
                                        {  
                                            r["Objects"][key] = response;
                                            chrome.storage.local.set({'Objects': r[key]});
                                        });
                                    });

      }
  });

}

If the value of profileContainers.length then in r["Objects"] at the end I will have only 5 elemens. Seems that value is overwritten. Now I can syncronize this object? :)

0 Answers
Related