One of my attempts so far has been:
array = [1, 2, 4, 5];
definir = function() {
switch (array) {
case (array > 1):
array.push(1);
break;
case (array > 2):
array.push(2);
break;
case (array > 0):
array.push(3);
break;
}
// Comparar elementos duplicado dentro de um vetor
var checar = array.filter(function(valor, i) {
return array.indexOf(valor) == i;
})
alert(checar);
}
<button onclick="definir();">Definir e Verificar</button>
I'm looking to add new elements that are within a case
option in array
.
But first check if array
finds the same element, to avoid duplicating!