javascript - FileList 和 File[](又名文件数组)之间有什么区别

标签 javascript angular typescript drag-and-drop

<分区>

当我在浏览器中收到文件丢弃时,我得到一个 FileList目的。这种类型的目的是什么?据我所知,它几乎与 Typescript File[] 或一个很好的旧 JavaScript 文件对象数组相同。

据我所知,FileList 较差,因为您不能使用其中之一迭代值或索引

for (let file of files) {
  // read file
}

for (let index in files) {
  // read files[index]
}

我也没有看到历史原因,因为 ArrayFile应该至少和 FileList 一样长。

我是不是漏掉了什么?

最佳答案

看来您完全正确 - 来自 official specification :

Note: The FileList interface should be considered "at risk" since the general trend on the Web Platform is to replace such interfaces with the Array platform object in ECMAScript [ECMA-262]. In particular, this means syntax of the sort filelist.item(0) is at risk; most other programmatic use of FileList is unlikely to be affected by the eventual migration to an Array type.

这个接口(interface)比较老,和NodeList很像尽管后者有点现代化。

关于javascript - FileList 和 File[](又名文件数组)之间有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48669122/

相关文章:

css - 如何减少透明度堆栈组件标签的宽度

typescript - 为我自己的 JavaScript 文件编写 .d.ts 文件

angular - 将对象数组转换为类实例

javascript - 显示父 UL 并为根父节点显示 UL 和 LI 节点

javascript - Flexslider 100% 宽度创建水平滚动条

javascript - Angular - 为什么 Number.isNaN 对于非空字符串返回 false?

javascript - github 上的 Angular 全栈示例

typescript - 扩展 typescript 变量声明

javascript - jquery window.open 在 ajax 成功中被阻止

javascript - 在 Javascript ES6 map 中获取或设置元素?