xxxxxxxxxx
const array = ['apple', 'banana', 'orange', 'banana', 'kiwi'];
const uniqueArray = [new Set(array)];
console.log(uniqueArray);
xxxxxxxxxx
var arr = [55, 44, 65,1,2,3,3,34,5];
var unique = [new Set(arr)]
//just var unique = new Set(arr) wont be an array
xxxxxxxxxx
const myArray = ['a', 1, 'a', 2, '1'];
const unique = [new Set(myArray)]; // ['a', 1, 2, '1']
xxxxxxxxxx
const array = [1, 2, 3, 4, 4, 5, 3, 2];
// Using Set to remove duplicates
const uniqueArray = [new Set(array)];
console.log(uniqueArray);
xxxxxxxxxx
// one liner solution to get a unique array by object id
[{_id: 10},{_id: 20}, {_id: 20}].filter((item, i, ar) => ar.findIndex(each => each._id === item._id) === i)
xxxxxxxxxx
<?php
// app.php
$data = [19, 21, 19, 21, 46, 21, 29, 21, 18];
print_r(array_unique($data));
xxxxxxxxxx
const array = [1, 2, 3, 1, 2, 4, 5, 3, 6, 4];
const uniqueElements = [new Set(array)];
console.log(uniqueElements);
xxxxxxxxxx
const array = [2,5,7,5,6,4,2,4,5,8,412,477,36,8,2,34,7]
const generateUniqueArray => arr => [ new Set(arr)]
const result = generateUniqueArray(array)
console.log(result) // [ 2, 5, 7, 6, 4, 8, 412, 477, 36, 34]
// With love @kouqhar
xxxxxxxxxx
// Example array
const array = [1, 2, 2, 3, 4, 4, 5, 6, 6];
// Using Set to get unique values
const uniqueValues = [new Set(array)];
console.log(uniqueValues); // Output: [1, 2, 3, 4, 5, 6]