我有一个对象数组,如下所示:
const data = [
{ depth: 0, length: 5 },
{ depth: 1, length: 8 },
{ depth: 1, length: 11 },
{ depth: 1, length: 6 },
{ depth: 1, length: 8 },
{ depth: 1, length: 11 },
{ depth: 1, length: 6 },
{ depth: 1, length: 8 },
{ depth: 2, length: 16 },
{ depth: 2, length: 25 }
];
我需要获取每个键的最高值。我想要的数组是:lengthdepth
const result = [
{ depth: 0, length: 5 },
{ depth: 1, length: 11 },
{ depth: 2, length: 25 }
];
数组可以是 X 深度。我见过的其他示例仅获得最大值,或具有最大值的单个对象,而我需要每个键的最大值。data
MM们
相关分类