Within a certain key, I am storing an array with values in this format:
{id: 0, data: mydata}
Additionally, there is a corresponding list for each ID, used for file deletion and element removal.
The issue arises when attempting to delete an object from the array using the JavaScript splice function, as it alters the index values.
Refer to the JavaScript code snippet below:
function setupFileList(file, id){
var list_of_file = document.getElementById("list_of_file");
var name_of_file = file.name;
var size_of_file = 0;
var file_reader = new FileReader();
file_reader.onload = function(e){
var imgsrc = e.target.result;
if(file){
if(file.size > 1024 * 1024)
size_of_file = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + "MB";
else
size_of_file = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';
}
list_of_file.innerHTML += '<div id="file-'+id+'" class="filesUp"><img class="imgUp" src="' + imgsrc +'" width="100px" height="100px"><div class="progressUp"><span>' + name_of_file + ' / ' + size_of_file +'</span></div><a href="#" onclick="deleteUp(\''+id+'\')">Delete</a></div>';
};
file_reader.readAsDataURL(file);
};
function deleteUp(fid){
var file_query = fileQuery.indexOf({id: fid});
fileQuery.splice(file_query, 1);
console.log(file_query);
}