FileList
不是Array
,但它确实符合合同(有length
和数字指数),所以我们可以"borrow "Array
方法:
Array.prototype.forEach.call(field.photo.files, function(file) { ... });
因为你显然在使用ES6,所以你也可以使用新的Array.from
方法将其设置为Array
:
Array.from(field.photo.files).forEach(file => { ... });