I have an Array with duplicate objects, and I want to remove those duplicate objects. But I can't seem to find a proper solution for it. What is my mistake over here?
The object is as below.
{name: "login", text: "Login"}
{name: "navigation", text: "Navigation"}
{name: "landing", text: "Landing Page"}
{name: "login", text: "Login"}
{name: "navigation", text: "Navigation"}
{name: "landing", text: "Landing Page"}
Below is my code where items
has the array of objects.
this.subMenuItems = this.items.reduce((acc, current) => {
const x = acc.find(item => item.name === current.name);
if (!x) {
return acc.concat([current]);
} else {
return acc;
}
}, []);
Also you can refer the screenshot of the Console.log of the items
variable