javascriptobjectfilelist

Is it possible to combine two FileList objects?


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?


Solution

  • 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));