来点es6魔法怎么样?
things.thing = things.thing.filter((thing, index, self) =>
  index === self.findIndex((t) => (
    t.place === thing.place && t.name === thing.name
  ))
)
参考网址
更通用的解决方案是:
const uniqueArray = things.thing.filter((thing, index) => {
  const _thing = JSON.stringify(thing);
  return index === things.thing.findIndex(obj => {
    return JSON.stringify(obj) === _thing;
  });
});
使用上述属性策略而不是JSON.stringify:
const isPropValuesEqual = (subject, target, propNames) =>
  propNames.every(propName => subject[propName] === target[propName]);
const getUniqueItemsByProperties = (items, propNames) => 
  items.filter((item, index, array) =>
    index === array.findIndex(foundItem => isPropValuesEqual(foundItem, item, propNames))
  );
如果您希望propNames属性是数组或值,则可以添加包装器:
const getUniqueItemsByProperties = (items, propNames) => {
  const propNamesArray = Array.from(propNames);
  return items.filter((item, index, array) =>
    index === array.findIndex(foundItem => isPropValuesEqual(foundItem, item, propNamesArray))
  );
};
允许getUniqueItemsByProperties('a')和getUniqueItemsByProperties(['a']);
Stackblitz 示例
解释
- 首先了解所使用的两种方法:
 
- 接下来想想是什么让你的两个对象相等,并记住这一点。
 
- 我们可以将某物检测为重复,如果它满足我们刚刚想到的标准,但它的位置不在具有该标准的对象的第一个实例上。
 
- 因此,我们可以使用上述标准来确定某些内容是否重复。