Checking Whether Javascript Array Numbers are Unique | Task

Ole Ersoy
Oct - 14  -  1 min

Scenario

We have an array [1,2,3] and we want to know whether the numbers are unique.

Approach

function isArrayUnique(target: any[]): boolean {
const uniqueItems = target.filter((a, b, c) => c.indexOf(a) === b);
   return target.length === uniqueItems.length;
}

Demo