$array = [
0 => 0,
1 => 0,
2 => 1,
3 => 1,
4 => 2,
5 => 2,
6 => 3,
7 => 3,
8 => 4,
9 => 4
];
$arrUnique = array_unique($array);
echo '<pre>';
print_r ($arrUnique);
echo '</pre>';
Array
(
[0] => 0
[2] => 1
[4] => 2
[6] => 3
[8] => 4
)
let array = {
0: 0,
1: 0,
2: 1,
3: 1,
4: 2,
5: 2,
6: 3,
7: 3,
8: 4,
9: 4
};
let arrUnique = array_unique(array);
const uniqueObj = (obj, key = val => val) =>
Object.fromEntries(Object
.entries(obj)
.filter(function(n) {
const k = key(n[1], n[0]);
return !this.has(k) && this.add(k);
}, new Set)
);