var data = [
{ date: "2017-04-20", price: 1170 },
{ date: "2017-04-21", price: 1450 },
{ date: "2017-04-22", price: 960 },
{ date: "2017-04-25", price: 2300 },
{ date: "2017-05-21", price: 1203 },
{ date: "2017-05-22", price: 1206 },
{ date: "2017-03-20", price: 658 }
];
var monthMap = {};
data.forEach(function (n) {
var month = n.date.substring(0, 7);
if (!monthMap[month] || monthMap[month] > n.price) {
monthMap[month] = n.price;
}
});
// {2017-04: 960, 2017-05: 1203, 2017-03: 658}
console.log(monthMap);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…