我有一个遵循以下格式的数组:
[{"id":1,"date":"2019-09-05T00:00:00.000"},{"id":1,"date":"2019-06-05T00:00:00.000"},
{"id":2,"date":"2019-07-05T00:00:00.000"},{"id":2,"date":"2019-04-05T00:00:00.000"}]
我想要过滤此数组,以便对于每个id,我都能获得最新的日期值。
因此在给定的示例中,我想返回:
[{"id":1,"date":"2019-09-05T00:00:00.000"},{"id":2,"date"="2019-07-05T00:00:00.000"}]
答案 0 :(得分:1)
{}
,其键将是ID的然后您将拥有一个类似的对象:
{
"id1" : "<biggest date having this id>",
"id2" : "<biggest date having this id>",
...
}