1var arr = [55, 44, 65,1,2,3,3,34,5];
2var unique = [...new Set(arr)]
3
4//just var unique = new Set(arr) wont be an array
1let a = ["1", "1", "2", "3", "3", "1"];
2let unique = a.filter((item, i, ar) => ar.indexOf(item) === i);
3console.log(unique);
1// usage example:
2var myArray = ['a', 1, 'a', 2, '1'];
3var unique = myArray.filter((v, i, a) => a.indexOf(v) === i);
4
5// unique is ['a', 1, 2, '1']
1function onlyUnique(value, index, self) {
2 return self.indexOf(value) === index;
3}
4
5// usage example:
6var a = ['a', 1, 'a', 2, '1'];
7var unique = a.filter(onlyUnique);
8
9console.log(unique); // ['a', 1, 2, '1']
1import java.util.Random;
2
3public class GenRandArray {
4 //Recommend reseeding within methods
5 static Random rand = new Random();
6
7 public static void fillInt( int[] fillArray ) {
8 //seeds the random for a new random each method call
9 rand.setSeed(System.currentTimeMillis());
10
11 for(int i = 0; i < fillArray.length; i++)
12 {
13 fillArray[i]= rand.nextInt();
14
15 /* for loop to check to make sure that none of the previous
16 numbers added are the same as the one just added. */
17 for (int j = 0; j < i; j++)
18 {
19 /* if so we need to redo the last random number by
20 moving i back one index to be re-set */
21 if (fillArray[i] == fillArray[j])
22 {
23 i--;
24 }
25 }
26 }
27 }
28}