xxxxxxxxxx
function uniqueArray2(arr) {
var a = [];
for (var i=0, l=arr.length; i<l; i++)
if (a.indexOf(arr[i]) === -1 && arr[i] !== '')
a.push(arr[i]);
return a;
}
Unique Array
Filter out duplicate values from an Array.
xxxxxxxxxx
const arr = ["a", "b", "c", "d", "d", "c", "e"]
const uniqueArray = Array.from(new Set(arr));
console.log(uniqueArray); // ['a', 'b', 'c', 'd', 'e']
xxxxxxxxxx
//On Of The Best Or Eassy Method In Find Dublicate Or Unique Value Array In Javascript
const dublicatNum = [5, 5, 6, 7, 6, 7, 7, 1, 3, 3, 3, 5, 6, 8, 2, 4];
const language=['Html','Css','Html','Css','Html','Css','Php','Js','Php','Python'];
function findDubArray(array) {
const result = array.sort().sort((a,b)=>a-b).filter((val, index, ary) => ary.indexOf(val) === index && ary.lastIndexOf(val) !== index)
return result
}
console.log(findDubArray(dublicatNum));//[ 3, 5, 6, 7 ]
console.log(findDubArray(language));