Skip to content

Instantly share code, notes, and snippets.

@hawx1993
Created January 5, 2022 08:11
Show Gist options
  • Select an option

  • Save hawx1993/206ec5e9a02f627e61577663b2c06cfa to your computer and use it in GitHub Desktop.

Select an option

Save hawx1993/206ec5e9a02f627e61577663b2c06cfa to your computer and use it in GitHub Desktop.
// 数组去重对象
var arr = [
{ id: 1, city: "南京" },
{ id: 2, city: "南京" },
{ id: 3, city: "杭州" },
{ id: 4, city: "广州" },
];
var newArr = arr.reduce((prev, cur) => {
obj[cur.city] ? "" : (obj[cur.city] = true && prev.push(cur));
return prev;
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment