lundi 28 juin 2021

Javascript random items from array without repeat on same position (Loops)

I have this array:

var colors = new Array("RED", "BLUE", "WHITE", "BLACK", "LIME", "YELLOW");

and I need select with LOOP function, (e.g. five times) random items but without repeating the items in the same position:

red, blue, white, black, lime, yellow - is ok

blue, white, lime, red, yellow, black - is ok

white,black, red, lime, red, yellow - is not ok, yellow is in the same position as before ... etc...

Can you help me?




Aucun commentaire:

Enregistrer un commentaire