I have the next situation in my react application:
I have a state:
const [arr1, setArr1] = useState([1, 2, 3, 5, 1, 3]);
Bellow i render all items from array on UI like:
arr1.map(i => <li>{i}</li>)
Now i want to remove all items that are equal in the array:
ex:
- [1, 2, 3, 5, 1, 3] // should be deleted 1 and 3 result: [1, 2, 5]
- [1, 2, 3, 5, 3] // should be deleted 3 result: [1, 2, 5]
Deleting all items also the state should change herearr1.map()
.
I triedsetArr1([new Set(arr1)])
, but it does not delete all duplicated values, it delete just one of them.
How to achieve what i described above?