constlist=[{id:1,info:'西瓜'},{id:1,info:'西瓜'},{id:2,info:'草莓'},{id:3,info:'榴蓮'},{id:3,info:'榴蓮'},{id:4,info:'蘋果'}]consthash={};constarr=list.reduce(function(item,next){hash[next.id]?'':(hash[next.id]=true&&item.push(next));returnitem;},[]);數組的值是對象,然后通過reduce方法去掉ID重復的值,問題就是我感覺還是有點繁瑣,現在的問題是如果別人看的話還需要理解一下子,有沒有更簡潔明了的寫法,或者什么工具類比如lodash什么的方法推薦,謝謝
新手上路,數組去重,數組的值是對象。
慕絲7291255
2019-11-03 09:56:00