0

// Here push function is not working

    var durations = []
    files.forEach(doc => {

        getVideoDurationInSeconds(`uploads/skill1/${doc}`).then((duration) => {
            
            durations.push(duration)    // Here push fuction is not working 
        })
        
        
    });

    console.log(durations)

// Here Push function is working

    var durations = []
    files.forEach(doc => {

        getVideoDurationInSeconds(`uploads/skill1/${doc}`).then((duration) => {
            
        })
        
        durations.push(doc)    // Here push fuction is working 
        
    });

    console.log(durations)

I want to store the duration of videos in array, i am getting all the duration of videos but not able to push in array. I am using nodejs and get-video-duration package

  • you can use await instead of .then with getVideoDurationInSeconds – Waelsy123 Mar 30 '21 at 15:31
  • var durations = [] files.forEach(async doc => { const duration = await getVideoDurationInSeconds(`uploads/skill1/${doc}`) durations.push(duration) // Here push fuction is working }); console.log(durations) – Waelsy123 Mar 30 '21 at 15:31
  • 1
    @Waelsy123 thanks dear... you were right.... i simply put my that in .finally(){}... thanks – Umer Affaq Mar 30 '21 at 15:48

0 Answers0