I am trying to remove duplicate words from the string that I stored in an object like this.
const myObj = {
name: "rishi rishi",
college: "mnit mnit"
};
This is my code to remove duplicate words.
const removeDuplicate = (str) => {
return [...new Set(str.split(" "))].join(" ");
};
for (const key in myObj) {
removeDuplicate(myObj[key]);
}
But this code doesn't remove the duplicate word, it just returns the original string.
Anyone, please help me with this.