Skip to content

findDuplicates

The findDuplicates() function returns duplicated values from an array and keeps a single occurrence for each duplicated value.

Interactive example

Syntax

Classic signature

typescript
function findDuplicates<
  GenericInput extends readonly EligibleDuplicateElement[],
>(
  array: GenericInput,
): undefined | AnyTuple<GenericInput[number]>

Parameters

  • array: Input array to scan for duplicates.

Return value

Returns undefined when no duplicate is found, otherwise returns a tuple containing duplicated values (one occurrence per value).

See also

  • find - Finds a value matching a predicate
  • group - Groups values by key
  • includes - Checks value presence in an array

Released under the MIT license.