I have a FileList object which holds previously uploaded documents. I'm trying to use another function to add more files to this collection, by using another FileList object, so I need to "append" the secondary FileList object onto the primary one. How would it be possible to achieve this?
One way to let us loop through each item in a file list object is to convert it to an array with the Array. from method. Then we can use the forEach method on it to loop through the file list entries. The file input has the multiple attribute so that we can select multiple files.
A FileList is an array-like object that represents a collection of File objects returned by the files property of the HTML <input> element. You can use this to access the list of files selected with the <input type="file"> element.
FileList is a command-line utility that generates a CSV file listing the contents of a given directory. By default, the list includes the file name, size, and path, as well as the last-access, last-modified, and creation dates, etc. You can easily import all results to a spreadsheet or database.
You have to first convert the FileList
objects to Arrays, after which you can simply concat
the multiple arrays.
const joined = Array.from(fileListA).concat(Array.from(fileListB));
const filesArray = [...filesList1, ...filesList2];
console.log(filesArray) // [File, File, File, File, File, ...]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With