I need to remove an element from the array by index, for example:
arr = [1,2,3,4,5,6]
When removing the index element 3:
arr = [1,2,3]
It needs to remove everything after the index entered including the index.
I tried to do this:
var localUltimo = w_history.length - 1;
var anterior = w_history[localUltimo];
// var ultimo = w_history.pop();
for(var i = 0; i < w_history.length; i++){
console.log("tam " + w_history[i] + " ultm " + anterior);
if(w_history[i] == anterior){
w_fim = i;
break;
}
}
console.log("w_fim " + w_fim);
console.log("tamanho " + w_history.length);
while(w_history.lenght > w_fim){
console.log("w_fim " + w_fim);
console.log("tamanho " + w_history.length);
w_history.pop();
}
var ref = w_history[localUltimo - 1];
console.log("ref " + ref)
activate_page(ref, '1');
w_history.slice(0, ref)
console.log(w_history);
But the result was not satisfactory when running it adds a undefined
element and immediately after cleaning every array:
ARRAY BEFORE:
["#login", "#listar_CELULAS", "#minha_CELULAS", #listar_CELULAS]
ARRAY AFTER:
["#login", "#listar_CELULAS", "#minha_CELULAS", "#listar_CELULAS", "#minha_CELULAS"]
Thank you.