2017-05-12 93 views
0

我有一系列项目matchingItemsCurrentRow。它有IBwFormSectionItem其中有一个属性runCount项目。我想获得具有最大值runCount的数组项目。我怎么才能得到它?如何获得阵列项目中具有最大属性值的阵列项目

IBwFormSectionItem的类型定义如下:

export interface IBwFormSectionItem { 
    meta?: IBwFormItemMetadata[], 
    font?: IBwFormFont, 
    col?: number, 
    row?: number, 
    colSpan?: number, 
    rowSpan?: number, 
    text?: string, 
    runs?: boolean, 
    runCount?: number, 
    height?: number, 
    width?: number 
} 
+2

请发布您使用JSON格式的数据以及预期的输出。 – Bergi

+0

此问题已被询问和回答多次。大多数解决方案都使用'reduce'来遍历项目。 –

+0

没有得到笏你试图做。如果你想从数组中获得最大值尝试这个代码... Math.max.apply(this,[1,2,3,4]); – subbu

回答

0

我就是这么做的指torazaburo的评论。

maxRunCountItem = matchingItemsCurrentRow.reduce((item1, item2) => {       
    return item1.runCount > item2.runCount ? item1 : item2; 
});