我有JSON數組這樣,如何從JSON數組中刪除重複的對象
daysdif = [{
"EmployeeID": "213654654",
"DaysDiff": "NaN"
}, {
"EmployeeID": "String",
"DaysDiff": "NaN"
}, {
"EmployeeID": "6021240",
"DaysDiff": "-63.30"
}, {
"EmployeeID": "6011327",
"DaysDiff": "-35.67"
}, {
"EmployeeID": "883",
"DaysDiff": "-63.40"
}, {
"EmployeeID": "1183",
"DaysDiff": "-70.13"
}, {
"EmployeeID": "1240",
"DaysDiff": "-70.97"
}, {
"EmployeeID": "2293",
"DaysDiff": "-63.30"
}, {
"EmployeeID": "5001839",
"DaysDiff": "-8.47"
}, {
"EmployeeID": "5001839",
"DaysDiff": "-22.20"
}, {
"EmployeeID": "5001839",
"DaysDiff": "-23.77"
}, {
"EmployeeID": "5001839",
"DaysDiff": "-41.67"
}, {
"EmployeeID": "5001839",
"DaysDiff": "-63.97"
}, {
"EmployeeID": "3395",
"DaysDiff": "-68.00"
}, {
"EmployeeID": "2473",
"DaysDiff": "-66.20"
}, {
"EmployeeID": "1075",
"DaysDiff": "-70.17"
}, {
"EmployeeID": "2947",
"DaysDiff": "-69.10"
}, {
"EmployeeID": "5002196",
"DaysDiff": "-4.97"
}, {
"EmployeeID": "5002196",
"DaysDiff": "-39.23"
}, {
"EmployeeID": "5002196",
"DaysDiff": "-58.73"
}, {
"EmployeeID": "1688",
"DaysDiff": "-67.40"
}, {
"EmployeeID": "2031",
"DaysDiff": "-54.07"
}, {
"EmployeeID": "1484",
"DaysDiff": "-69.17"
}, {
"EmployeeID": "1022",
"DaysDiff": "-69.40"
}]
有這JSON數組一樣重複的值,
[{
"EmployeeID": "5001839",
"DaysDiff": "-8.47"
}, {
"EmployeeID": "5001839",
"DaysDiff": "-22.20"
}, {
"EmployeeID": "5001839",
"DaysDiff": "-23.77"
}, {
"EmployeeID": "5001839",
"DaysDiff": "-41.67"
}, {
"EmployeeID": "5001839",
"DaysDiff": "-63.97"
}]
我需要保持最高DaysDiff值(在這裏-8.47)並刪除其他重複。
你嘗試過什麼? – Rajesh
是的,我可以刪除重複的EmployeeID,但我需要保持最高的DaysDiff值。 – Hashan
在上面的提及中,@aefxx只是取代了最後一個值。相反,檢查對象是否具有該鍵,如果是,則分配'Math.max(ObjectValue,CurrentValue)' – Rajesh