I have been experimenting with dropzoneJS and I am looking for a way to retrieve the index of a specific file in the list. This is because I need to remove an element from an array that is associated with the file I uploaded.
To do this, I created an array named uploadedImages
.
var uploadedImages = []; //I managed to save the image array from the database somehow
My goal is to add the file names to the uploadedImages
array when the addedfile
function is triggered.
myDropzone.on("addedfile", function(file) {
uploadedImages.push(file.name);
});
Then, when a file is removed, I want to filter out the images from the uploadedImages
array. However, I initially used the file.name
from Dropzone to do this. What if I have multiple images with the same name or I accidentally upload the same file more than once? I believe it would be more efficient to find the index instead.
myDropzone.on("removedfile", function(file) {
var filterUpload = uploadedImages.filter(function(img_file){
return img_file != file.name;
});
uploadedImages = filterUpload;
});
If you have any suggestions, please feel free to share. Thank you in advance!