set unique array javascript code example
Example 1: js unique using set
let uniqueArray = [...new Set([5,5,2,2,2,4,2])];
Example 2: javascript array unique values
var arr = [55, 44, 65,1,2,3,3,34,5];
var unique = [...new Set(arr)]
Example 3: array unique values javascript
const myArray = ['a', 1, 'a', 2, '1'];
const unique = [...new Set(myArray)];
Example 4: how to create an array with unique values
import java.util.Random;
public class GenRandArray {
static Random rand = new Random();
public static void fillInt( int[] fillArray ) {
rand.setSeed(System.currentTimeMillis());
for(int i = 0; i < fillArray.length; i++)
{
fillArray[i]= rand.nextInt();
for (int j = 0; j < i; j++)
{
if (fillArray[i] == fillArray[j])
{
i--;
}
}
}
}
}