How to Check for Duplicate Names in an Array Online

This tool helps you easily find duplicate lines and count the number of repetitions and get distinct values.

Having duplicate names in array lists can cause confusion, errors, and inefficiency. Finding and eliminating duplicates is critical to maintaining accurate data management and organization. By actively searching for duplicate names, you can optimize your workflows and increase the overall quality of your data. Our handy tool simplifies this task by highlighting repeated names with a single click, saving you time and effort.

It's super simple to find duplicate names in an array. Just input your list of names or JavaScript array, click once, and you'll instantly see the duplicate names listed separately.

Note: The data you enter in the text box is processed locally in your web browser. We do not collect any data.

Add your names list or javaScript array

How to use this, follow these steps
  1. Select data type [name list, array, other]

  2. Add your text

  3. click the 'Check duplicates' button

  4. You can see duplicate names and unique value below

Add the JavaScript array without assigning it to a variable var arrya_name = [] Add anonymous array ["...", "...", "..."]

Add the JavaScript array of object without assigning it to a variable var arrya_name = [] Add anonymous array object [{"..."}, {"..."}, {"..."}]

Total 4
Duplicate 1
Unique 3
# Value Type Duplicate count
1applestring1

Output code

Select what type code you want copy or download

How To Extract distinct Values From Arrays Using JavaScript

To remove duplicate values from an array in JavaScript, use the Set object. Create a new set with new Set(array), which automatically removes duplicates, then convert it back to an array with Array.from() or use the spread operator [...new Set(array)]. Both methods are efficient and leverage JavaScript's built-in data structures to retain only unique elements. Here is the example code

JavaScript
const get_unique_value = arr => [...new Set(arr)];
usage
const array = ["orange", "apple", "apple", "orange"];
const unique_value = get_unique_value(array);
console.log(unique_value);
// Output: ["orange", "apple"]

How To Get Only Duplicates with JavaScript

To get only the duplicate values in an array using JavaScript, you can use a combination of objects and array methods like new Map(). Here's an example function

JavaScript
const get_duplicates = arr => {
    const unique_items = new Map();
    const duplicates = [];
    // Count occurrences of each elements
    arr.forEach(item => {
        if (unique_items.has(item)) {
        	// increase duplicate count
            unique_items.set(item, unique_items.get(item) + 1);
        } else {
        	// add to unique list
            unique_items.set(item, 1);
        }
    });
    // Collect item with count greater than 1
    unique_items.forEach((count, item) => {
        if (count > 1) {
            duplicates.push(item);
        }
    });
    return duplicates;
}
usage
const array = ["orange", "apple", "orange", 1, "1", true, false, false];
const duplicates = get_duplicates(array);
console.log(duplicates);
// Output: ["orange", false]

How To Remove Duplicate Objects From An Array

To remove duplicate objects from an array in JavaScript, especially when the objects have a unique identifier (such as an id), you can use a combination of filter and map methods. Here's an example function using new Map()

JavaScript
const object_unique = (arr, key) => {
    return [...new Map(arr.map(item => [item[key], item])).values()];
};
usage
const array = [
  { id: 1, name: "orange" },
  { id: 2, name: "apple" },
  { id: 2, name: "banana" },
  { id: 3, name: "grapes" },
];
// function parameter (array object, property name)
const unique_object = object_unique(array, "id");
console.log(unique_object);
/* Output:
[{ id: 1, name: "orange" },
{ id: 2, name: "banana" },
{ id: 3, name: "grapes" }]
*/

Explanation:

  1. Mapping:

    JavaScript
    arr.map(item => [item.id, item])

    This results in:

    JavaScript
    [
      [1, { id: 1, name: "orange" }],
      [2, { id: 2, name: "apple" }],
      [2, { id: 2, name: "banana" }],
      [3, { id: 3, name: "grapes" }]
    ]
  2. Creating a Map:

    JavaScript
    new Map(arr.map(item => [item.id, item]))

    The Map will process the pairs and only keep the last pair for each id. So the result will be:

    JavaScript
    Map {
      1 => { id: 1, name: "orange" },
      2 => { id: 2, name: "apple" },
      3 => { id: 3, name: "grapes" }
    }
  3. Extracting Values:

    JavaScript
    [...new Map(arr.map(item => [item.id, item])).values()]

    This converts the Map values into an array:

    JavaScript
    [
      { id: 1, name: "orange" },
      { id: 2, name: "apple" },
      { id: 3, name: "grapes" }
    ]

    This effectively filters out duplicates, keeping only the last occurrence of each unique id.


This page was last modified on