Supposed I have a response of
and I'm looping it via and push the pic.id on files array
files = []
response.data[0].pics.forEach(function(pic, i){
let div = makeButtons(response.data[0].pics, files, imgPrevEdit);
files.push(pic.id);
});
so after pushing the file array will become like this
the make button function is use to delete that certain element on the array using splice function
makeButtons: function(file, store, elem) {
let button = document.createElement("button");
button.classList.add('position-absolute','x', 'rounded-circle');
button.type = "button";
button.innerHTML= "x";
button.addEventListener('click', () => {
elem.removeChild(div);
store.splice(store.indexOf(file), 1);
});
let div = document.createElement("div");
div.classList.add('col', 'mt-2');
div.appendChild(button);
return div;
},
However when i click the button it always start at the end of files array it doesnt find the specific key and delete it
any idea how can i solve it?