9
Well I’m needing to remove an element from the array by index, for example:
arr = [1,2,3,4,5,6]
When removing index element 3:
arr = [1,2,3]
It is necessary that he remove everything after the reported index including the index.
I tried to do it this way:
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 executing it adds an element undefined
and then clean up the whole array:
ARRAY BEFORE:
["#login", "#listar_CELULAS", "#minha_CELULAS", #listar_CELULAS]
ARRAY LATER:
["#login", "#listar_CELULAS", "#minha_CELULAS", "#listar_CELULAS", "#minha_CELULAS"]
Thank you.
You want to remove index element 3 and all later?
– Guilherme Lautert
Exactly, this is what I need
– Renan Rodrigues
It would be complicated by the actual array, before and after?
– Guilherme Lautert
I edited the question
– Renan Rodrigues
Sorry Renan still not understood what you want, what I understood is that you remove the first element and concatenated the array with the own array without the first element
– Guilherme Lautert