has-duplicate

Returns true if an array has duplicate elements

Usage no npm install needed!

<script type="module">
  import hasDuplicate from 'https://cdn.skypack.dev/has-duplicate';
</script>

README

has-duplicate

Build Status

Returns true if an array has duplicate elements.

Based on find-indices-of-duplicates.

Install

npm install has-duplicate --save

API

has-duplicate

Parameters

  • array Array The array to check
  • comparator Function The compare function (optional, default lodash.isequal)

Examples

import hasDuplicates from 'has-duplicate';

hasDuplicates([1, 2, 3]); // false
hasDuplicates([1, 2, 3, 1]); // true
hasDuplicates([{ v: 1 }, { v: 1 }]); // true
hasDuplicates([{ v: 1 }, { v: 2 }]); // false
hasDuplicates([{ v: 1 }, { v: 1 }], (a, b) => a === b); // false

Returns boolean True if has duplicates and false otherwise