unique

Creates a unique array from the input array.

1. Code

const unique = <T>(arr: T[]): T[] => {
  //@ts-ignore
  return [...new Set(arr)];
};

export default unique;

2. Installation

npx @jrtilak/lazykit@latest add unique

3. Description

The unique function is a utility function in JavaScript that takes an array and returns a new array with all duplicate values removed. The function uses set to remove duplicate values from the array.

4. Props

Prop

Type

Default Value

arr*any[]---

5. Examples

import unique from ".";

const arr = [1, 2, 3, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10];
const result = unique(arr);
console.log(result);
// Expected Output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]