我有想要获取最低价格的json对象。以下是响应。
[
{
"room": {
"price": 217,
"available": true
}
},
{
"room": {
"price": 302,
"available": true,
}
},
{
"room": {
"price": 427,
"available": true,
}
}
]
我已经尝试过Stackoverflow的解决方案,但万一无法使用。
var arr = Object.keys( response ).map(function ( key ) { return response[key]; });
var min = Math.min.apply( null, arr );
请帮忙
本机JS解决方案:
var t =[ { "room": { "price": 217, "available": true } }, { "room": { "price": 302, "available": true, } }, { "room": { "price": 427, "available": true, } } ]
var min = t.map(function(el){return el.room.price}).reduce(function(el){return Math.min(el)});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句