vendredi 22 novembre 2019

How to get an array of unique and random values from a given array of possible unique values in JavaScript

I want to get the random values from a given array of all possible unique values and i have tried these:

 var myArray = ['a', 1, 'a', 2, 1,3];
let unique = [...new Set(myArray)];
console.log(unique); 

and

var myArray = ['a', 1, 'a', 2, 1 ,3];
random = myArray [Math.floor(Math.random() * myArray .length)];

//desired result =[2,'a',3,1] or any random order but all the possible unique random values

but I didn't get my desired thing. I have also read all the questions about this but none of that helps me to achieve mine.




Aucun commentaire:

Enregistrer un commentaire