Hi Friends 👋,

Welcome To Infinitbility! ❤️

To remove duplicates from array in react js, use the new Set() method with it will create new array without dublicate elements.

The Set object lets you store unique values of any type, whether primitive values or object references.

To use new set in array you have to follow below syntax.

[...new Set(arr)]

Today, I’m going to show you How do I remove duplicates from array in react js, as above mentioned, I’m going to use the above-mentioned new Set() method to get only unique elements of array.

Let’s start today’s tutorial how do you remove duplicates from array in react js?

React js remove duplicates from array example

Here, we will create an array with some data, and then we will use the new Set() method to remove duplicates elements and store in a different variable.

import React, { useState, useEffect } from "react";
export default function App() {
  const [arr, setArr] = useState([

  useEffect(() => {
    setArr([...new Set(arr)]);
  }, []);

  return (
    <div className="App">

In the above example, I have created an array state with dublicate elements and make unique in a useEffect after that printed result in a screen.

I hope it helps you, All the best 👍.