Allow value to be repeated in JS

1

In the following section, it is verified if the value already exists inside the vector, if it does not exist it is inserted. I wish I could do this normal check, but allow the '0' to be repeated. Ex:

 v_patr = [1,2,3,0,4,5,0]; //onde só o '0' pode ser inserido novamente.
 w_valor //é o valor recebido como parâmetro!

    if ((v_vet.indexOf(w_valor) == -1) && (w_valor != ""))
            {               
                v_vet[w_Cont_Qtde] = w_valor;
                w_Cont_Qtde = w_Cont_Qtde + 1;  
            }
    
asked by anonymous 28.10.2014 / 12:21

1 answer

3

You just need to verify that the number being entered is equal to 0:

if ( (v_vet.indexOf(w_valor) == -1 && w_valor != "") || w_valor === 0) {               
   v_vet[w_Cont_Qtde] = w_valor;
   w_Cont_Qtde = w_Cont_Qtde + 1;  
}
    
28.10.2014 / 12:53