小编Moh*_*hir的帖子

根据月份和年份过滤对象数组

我想根据当前月份和年份显示对象

这将根据月份过滤对象,我也需要根据年份过滤对象。

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)

javascript arrays object typescript

5
推荐指数
1
解决办法
1970
查看次数

标签 统计

arrays ×1

javascript ×1

object ×1

typescript ×1