Delete selected data from array

1

In my role I enter data entered in an array and in a box for user viewing. But if he wants to remove this information, he selects it and is withdrawn through the function! But if he reports the same information again, it reports error already existing!

Ex:

variaveis na function
         w_Cont_Qtde = 1;
         w_Qtde_Peri = $arr_w_param[10]; --> $arr_w_param[10] é a quantidade informada em uma tela anterior (ex: 5 / 10 / ...) 
         v_patr = new Array (w_Qtde_Peri);

Inserts the data

function move(Origem, Destino)
{   
   var w_valor = Origem.value;  
 if (w_Cont_Qtde <=  w_Qtde_Peri)
    {        
    if ((v_patr.indexOf(w_valor) == -1) && (w_valor != ""))
       {
        var opt = document.createElement("option"); 
        opt.text = w_valor ;
        opt.value = w_valor ;
        Destino.options.add(opt);
        v_patr[w_Cont_Qtde]= w_valor;
        w_Cont_Qtde = w_Cont_Qtde +1;
        return true;
       }       
    else
        {   
        alert("Patrimônio OU Serial já existe OU não é válido!");
        return true;    
        }
   }
 alert("Quantidade informada ja Incluida !!!");
return true; 
}

Remove data (only deleting from the box)

function tira(Destino) 
{
    var i;
    for(i = 0; i < Destino.options.length; i++)
    { 
        if (Destino.options[i].selected && Destino.options[i].value != "")
        {
            w_valor=Destino.options[i].value;
            w_Cont_Qtde = w_Cont_Qtde - 1;
            Destino.remove(Destino.selectedIndex);
        }
    }
}

My problem is: "Delete the selected data from the array too, since it already deletes the box."

    
asked by anonymous 13.08.2014 / 16:53

1 answer

4

You can remove items from an array in javascript using the splice method , you enter in the first parameter the index of the item and in the second parameter the amount of items to remove.

Edited (Usage Example)

meuArray.splice(meuArray.indexOf(meuValor), 1);

that is, it will get the index of the item to remove from the array and will pass in the first parameter, and it will remove 1 item after this index (2nd parameter)

    
13.08.2014 / 17:14