JavaScriptのオブジェクトの配列から重複を削除する

1242 ワード

JavaScriptのオブジェクトの配列から重複を削除する


Sep 24 ' 20
5

 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)
Open Full Answer