2 回答
TA贡献1789条经验 获得超8个赞
Math.min您可以使用和的组合yourArry.map
像这样
Math.min.apply( Math, t[0].fareDetails.map(x=>x.baseFare))
var t =[{
"AC": "true",
"doj": "2020-11-20T00:00:00+05:30",
"fareDetails": [
{
"baseFare": "1033.00",
"srtFee": "0.0",
"tollFee": "0.0",
"totalFare": "1085.00"
},
{
"baseFare": "1086.00",
"srtFee": "0.0",
"tollFee": "0.0",
"totalFare": "1140.00"
},
{
"baseFare": "1190.00",
"srtFee": "0.0",
"tollFee": "0.0",
"totalFare": "1250.00"
},
{
"baseFare": "1243.00",
"srtFee": "0.0",
"tollFee": "0.0",
"totalFare": "1305.00"
}
],
"fares": [
"1250.00",
"1305.00",
"1140.00",
"1085.00"
],
},{
"AC": "true",
"doj": "2020-11-20T00:00:00+05:30",
"fareDetails": [
{
"baseFare": "12.00",
"srtFee": "0.0",
"tollFee": "0.0",
"totalFare": "1085.00"
},
{
"baseFare": "444.00",
"srtFee": "0.0",
"tollFee": "0.0",
"totalFare": "1140.00"
},
{
"baseFare": "22.00",
"srtFee": "0.0",
"tollFee": "0.0",
"totalFare": "1250.00"
},
{
"baseFare": "111.00",
"srtFee": "0.0",
"tollFee": "0.0",
"totalFare": "1305.00"
}
],
"fares": [
"1250.00",
"1305.00",
"1140.00",
"1085.00"
],
}]
var lowest =Math.min.apply(Math,t.flatMap(x=> x.fareDetails.map(x=>x.baseFare)))
console.log(lowest)
TA贡献1963条经验 获得超6个赞
您需要baseFare
从数组项中提取值并获取其中的最小值,如下所示。
Math.round(Math.min(...item.map(({ fareDetails: { baseFare } }) => Number(baseFare))));
添加回答
举报