我在数组arr中有这样的原始数据
[
{Id:1,
Date:20/06/2023,
ProdId:1
},
{Id:2,
Date:21/06/2023,
ProdId:1
},
{Id:3,
Date:21/06/2023,
ProdId:2
},
{Id:4,
Date:23/06/2023,
ProdId:2
},
{Id:5,
Date:20/06/2023,
ProdId:3
}
]
我想要的项目与独特的prodIds和它应该是最新的。我应该得到下面的数据
[
{Id:2,
Date:21/06/2023,
ProdId:1
},
{Id:4,
Date:23/06/2023,
ProdId:2
},
{Id:5,
Date:20/06/2023,
ProdId:3
}
]
我需要做什么?先谢谢你了!!
3条答案
按热度按时间xwbd5t1u1#
我相信可能有一个更简单的方法,但这对我来说很有效:
此代码首先按日期排序。然后根据
ProdId
筛选唯一值。lqfhib0f2#
诡计:
lp0sw83n3#
使用函数filterByProId: