Home > Mobile >  Cannot remove duplicates
Cannot remove duplicates

Time:09-11

I follow this question to achieve the result enter image description here

CodePudding user response:

Instead of looping over devicedetails, outside of the return, create a modified array using the spread syntax and set it as a new variable. Then loop over that instead.

e.g.

const array = ['test', 'testing', 'test', 'test1234', 'testing']

const updatedArray = [...new Set(array)]

console.log(updatedArray)

CodePudding user response:

You need to remove duplicates of the whole array and then map over the version with duplicates removed.

[...new Set(myArray)].map((devicedetails, index) => (
  <option key={index} value={devicedetails.groupName}>
    {devicedetails.groupName}
  </option>
));
  • Related