var array = [1, 2, 1, 10, 5, 3, 4, 40, 50],
i = array.length,
result = [];
array.sort(function (a, b) {
return a - b;
});
for (var i = 0; i < array.length; i++) {
array[i] != array[i - 1] && array[i + 1] != array[i] && result.push(array[i])
}
alert(result);
function arrayUnique(arr){
return arr.filter((e,i,a)=>a.indexOf(e)==i)
}
// test
console.info(arrayUnique([1, 2, 1, 10, 5, 3, 4, 40, 50])) // -> [1, 2, 10, 5, 3, 4, 40, 50]
console.info(arrayUnique([1, 2, 3, 1, 2, 33, 33, 55, 66])) // -> [1, 2, 3, 33, 55, 66]
console.info(arrayUnique(['privet', 'privet', 'kakdela'])) // -> ["privet", "kakdela"]