DEV Community

Md Abdullah al noor
Md Abdullah al noor

Posted on

Answer: Remove duplicates from an array of objects in JavaScript

 const things = [
  {place:"here",name:"stuff"},
  {place:"there",name:"morestuff"},
  {place:"there",name:"morestuff"}
];

const filteredArr = things.reduce((thing, current) => {
  const x = thing.find(item => item.place === current.place);
  if (!x) {
    return thing.concat([current]);
  } else {
    return thing;
  }
}, []);

    console.log(filteredArr)

Top comments (0)