[Solved] How to search object with the smallest value? [closed]


You need to take smaller than as condition and the numerical value, because you would compare strings., which goes wrong for '40' and '100', for example.

let intervals = [
        { id: "1", interval_start: "0", interval_end: "40" },
        { id: "2", interval_start: "41", interval_end: "65" },
        { id: "3", interval_start: "66", interval_end: "80" },
        { id: "4", interval_start: "81", interval_end: "100" }
    ],
    result = intervals.reduce((prev, current) =>
        +prev.interval_end < +current.interval_end ? prev : current
    );

console.log(result);

0

solved How to search object with the smallest value? [closed]