Created
January 5, 2022 08:11
-
-
Save hawx1993/206ec5e9a02f627e61577663b2c06cfa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 数组去重对象 | |
| 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