Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

array name stays and it duplicates and repeating this process just clogs the list up.

Thank you.

        setListItems(contents.data);
        console.log(contents.data);


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.8k views
Welcome To Ask or Share your Answers For Others

1 Answer

To convert the array contents.data to Set, do this:

const setData = new Set(contents.data);

That will remove all the duplicate items. Then to convert it back, do this:

const uniqueArray = Array.from(setData);

The above will only work if the original array (contents.data) consisted of primitive values. If it was an array of objects then this will not work as-is and will require some changes.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...