I have a simple drag and drop page in my website. It allows dragging and dropping files, and below code gives me a list of dropped files.
var files = e.target.files || (e.dataTransfer && e.dataTransfer.files);
So far, so good. Problem is that when I drag and drop more files, that files object will not append to list of files I already had. Say, I dropped 2 files for the first time. files variable has 2 files in that case. If I drop a third file, e.target.files will have only the third file.
I tried creating a global variable and doing += to append file list. But javascript treats that variable as a string by default. So, var selectedFiles += e.target.files treats the file list as a string.
How can I make it so I have a list of files appended everytime a file is dropped?
e.target.filesis a string - rather a list. So you would have to push (array.push()) each single file in files to your own list each time.var selectedFileList;instead ofvar selectedFileList = [];. That's why it was considering the variable as string. Updated declaration and used push instead of+=.