简体   繁体   中英

How to Use Object Destructuring with File Object

how to destructure an object like this?

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. I was able to iterate but that last part is missing

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

but I get an empty 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.

const { name, size } = FileObj

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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