我想根据当前月份和年份显示对象
这将根据月份过滤对象,我也需要根据年份过滤对象。
var array = [{
title: "a",
date: "2018-03-29"
}, {
title: "b",
date: "2018-04-13"
}, {
title: "c",
date: "2018-04-12"
}, {
title: "leave",
date: "2018-04-11"
}, {
title: "d",
date: "2018-06-16"
}],
currentMonth = new Date().getMonth() + 1,
events = array.filter(e => {
var [_, month] = e.date.split('-'); // Or, var month = e.date.split('-')[1];
return currentMonth === +month;
});
console.log(events);Run Code Online (Sandbox Code Playgroud)