简体   繁体   English

如何使用 Object 解构文件 Object

[英]How to Use Object Destructuring with File Object

how to destructure an object like this?如何像这样解构 object?

File {name: "file.png", lastModified: 1607110320000, lastModifiedDate: Fri Dec 
04 2020 11:32:00 GMT-0800 (Pacific Standard Time), webkitRelativePath: "", size: 
44887, …}

is a File from a FileList.是来自 FileList 的文件。 I was able to iterate but that last part is missing我能够迭代,但最后一部分丢失了

[...files].forEach((file, index) => (
    console.log({...file})
))}

but I get an empty object {}但我得到一个空的 object {}

Spreading the File object is not possible as it has no own properties,but you can destructure the File object and get the properties you need.传播文件 object 是不可能的,因为它没有自己的属性,但您可以解构文件 object 并获取您需要的属性。

const { name, size } = FileObj

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM