I need to remove one element from an array and return only the remaining elements.
I tried with splice and filter but can't get it to work.
With splice it only returns the removed element, I need the opposite.
var parse_obj = JSON.parse(document.getElementById('imagens').value);
function rImagem(data){
data = data - 1;
document.getElementsByClassName("btn_remover")[data].style.display = 'none';
parse_obj2 = parse_obj.splice(parse_obj.findIndex(e => e.data,1));
new_string = JSON.stringify(parse_obj2);
document.getElementById('imagens').value = new_string;
}
parse_obj?.splice()changes the array in-place, so once you runparse_obj.spliceit would be the array with the item removed.splice()method returns the deleted element from the array. You are trying to assign this deleted element in the arrayparse_obj2. What you should do is not assign anything to the variableparse_obj2and use theparse_objarray as it is.parse_obj.splice(parse_obj.findIndex(e => e.data,1));new_string = JSON.stringify(parse_obj2);