Convert file object to array of objects

I have a input form file picker which returns the following object output :

enter image description here

Image as text ->

FileList {0: File, 1: File, length: 2}
0: File {name: "Screenshot 2021-02-19 at 12.27.47 PM.png", lastModified: 1613717870763, lastModifiedDate: Fri Feb 19 2021 12:27:50 GMT+0530 (India Standard Time), webkitRelativePath: "", size: 81142, …}
1: File {name: "Screenshot 2021-02-18 at 12.11.00 PM.png", lastModified: 1613630510734, lastModifiedDate: Thu Feb 18 2021 12:11:50 GMT+0530 (India Standard Time), webkitRelativePath: "", size: 128961, …}
length: 2

I need to convert it to an array of objects of the form :

[{file0: file}, {file1: file}]

Please note that I don’t need the length item present in the initial object in the final array

14 thoughts on “Convert file object to array of objects”

Leave a Comment