logo

Uno.js

github

Unique - Array

Removes all duplicates from a array

Author: theatom06

Table of Contents

Import

import unique from 'https://uno.js.org/lib/array/unique.js';

and compresed version

import unique from 'https://uno.js.org/lib/array/unique.min.js';

Code

The raw code of the function is available here:

/**
 * Removes all duplicates from a array
 * @param {Array} array The array to remove duplicates from
 * @returns {Array} The array without duplicates
 * @example
 * unique([1, 2, 2, 3, 4, 4, 5]); // [1, 2, 3, 4, 5]
 * @author theatom06
 */
export default function unique(array) {
    return [...new Set(array)];
}

Parameters

  • array - The array to remove duplicates from

Returns

  • Array - The array without duplicates

Examples

unique([1, 2, 2, 3, 4, 4, 5]); // [1, 2, 3, 4, 5]