Can't use forEach with Filelist

前端 未结 6 623
栀梦
栀梦 2020-12-23 08:56

I\'m trying to loop through a Filelist:

console.log(\'field:\', field.photo.files)
field.photo.files.forEach(file => {
   // looping code
})
         


        
6条回答
  •  星月不相逢
    2020-12-23 09:11

    In ES6 you can use:

    [...field.photo.files].forEach(file => console.log(file));
    

    Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment

提交回复
热议问题