0

I have an array of items matchingItemsCurrentRow. It has items of type IBwFormSectionItem which has a property runCount. I want to get an array item which has the maximum runCount value. How can I get it?

The type definition of IBwFormSectionItem is given below:

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
}
A B C D
  • 19
  • 3
  • 2
    Please post the data that you have in JSON format, as well as the expected output. – Bergi May 12 '17 at 05:23
  • This question has been asked and answered many times. Most solutions use `reduce` to loop across the items. –  May 12 '17 at 05:31
  • didnt get wat your trying to do .if you want to get the max value from the array try this code ...Math.max.apply(this,[1,2,3,4]); – subramanian May 12 '17 at 05:32
  • I do not only want the max value but the whole object that has that max value. – A B C D May 12 '17 at 05:34

1 Answers1

0

I did it this way referring torazaburo's comment.

maxRunCountItem = matchingItemsCurrentRow.reduce((item1, item2) => {                        
    return item1.runCount > item2.runCount ? item1 : item2;
});
A B C D
  • 19
  • 3