How to delete a record already inserted in an array?

0

I hope you can help me with your support. On this screen I can select both LABELS only 1 time each and display the text of the Park label in the INPUT TEXT.

I MENTION THAT IT IS ALREADY VALIDATED SO THAT IT DOES NOT REPEAT THE SAME LABEL 2 TIMES IN THE INPUT TEXT, example "Park, Park", but when I obtain the data, that is to say the Arrangement of selected labels, if ADD THE LABEL THAT WAS SELECTED 2 TIMES "{1,1}" and should only have 1 time that value.

This is the code that I did:

function changeColor_1(x)
{
    array_valores2.push(x.innerHTML);
    array_ids2.push(x.id);

    var txtInput = document.getElementById('node2');
    var strValor = x.innerHTML;

    arrDatos2.pushIfNotExist(strValor, function (e) {
        return e === strValor;
    });

    txtInput.value = arrDatos2.toString();
}

out.println("<a class=\"btn desc fav w-button\" id=\"" + tipo.getCosa_id() + "\" name=\"parque\" onclick=\"javascript: changeColor_1(this)\" >" + tipo.getCosa_nom() + "</a>");

<input class="tf w-input" id="node2" maxlength="256" placeholder="Vida nocturna, el aeropuerto " type="text" required>

Thanks for your support!

    
asked by Ricardo Sauceda 04.10.2017 в 20:10
source

1 answer

1

This is an example for you to go through your arrangement and delete the "repeated" element:

var etiquetas = ["casa", "casa", "vaca", "toro"];
var buscarPor = "casa";

console.log('Estos son los elementos ANTES de buscar el elemento repetido:');
console.log(etiquetas);

for (var i = 0; i < etiquetas.length; i++) {
  if (buscarPor = etiquetas[i]) {
    etiquetas.splice(i, 1);
  }
}

console.log('Imprimo los resultados - solo para demostrar que el elemento repetido se ha eliminado:');
console.log(etiquetas);
    
answered by 04.10.2017 / 22:25
source