I'm trying to gather the times of all videos on a page and add them to an array. Here is the code:
var allvideos = $('video');
var times = [];
for ( i=0; i < allvideos.length; i++ ) {
allvideos[i].addEventListener('loadedmetadata', function() {
videoDuration = this.duration;
times.push(videoDuration);
});
};
If I console.log(times) within the EventListener, it works as expected but if I log it after the for loop it's empty. I can't figure out why that is. Could someone help, and please explain why? Thanks so much.
I am using jQuery and Video.js.
S