I am making a Chrome Extension, and I use the chrome.storage API in it. I am not putting my full code here (as its over 200 lines), but I'm putting enough that will probably show what I'm trying to do.

**Content Script (a script injected into a webpage due to my extension)**:

```
....
var videos = []
var imgs = []
var img = this.getElementsByTagName('img')
var video = this.getElementsByTagName('video')
for (i = 0; i <img.length; i++){
    if (img[i].className == "FFVAD"){
        imgs.push(img[i].src)
        addselection(img[i].parentNode.parentNode)
    }
}
for (i = 0; i <video.length; i++){
    if (video[i].className == "tWeCl"){
        videos.push(video[i].src)
        addselectionV(video[i].parentNode.parentNode)
    }
}

function addselectionV(e){
    e.style.border = "2px solid red"
    console.log(videos)
    for (var i = 0; i < videos.length; i++){
        chrome.storage.sync.set({['video'+i]: videos[i]}, function() {
          console.log('Value is set to ' + videos[i] + ' and key is set to ' + ['video'+i]);
    })

   chrome.storage.sync.set({vcount: videos.length}, function() {
      document.querySelector('.selectionbar').innerHTML = "Item(s) selected: "+videos.length
    });

```

}

I noticed that it wasn't working, so I added `console.log(videos)` to print the item in the array. It was there, so I did `console.log(videos[0])` and it was also there too. I looked in the developer console and noticed during my `for` loop, `videos.length` is returning undefined. Which is strange because I seem to have set everything up correctly. ([image of the console here](https://imgur.com/a/JGuwtgm))