I have an array, to which I am putting random numbers from 1 to 50.
What I need is to compare the next number with those inside the array to avoid having any repeated.
I have this:
//ARRAY con los numeros del 1 al 50
var aNumeros=[];
for (let intI =1; intI<=50; intI++)
aNumeros.push(intI);
//ARRAY EN DONDE QUIERO METER LOS NUMEROS
aElegidos.push(aNumeros.splice(parseInt(Math.random()*aNumeros.length), 1));
You could use
inArray
JQuery, with this you first verify if the value exists in the array, and based on that you decide what to do with it:I hope and serve you, and above all have understood you. Greetings.
Source: JQuery InArray