【问题标题】:date-fns check if date exist in arraydate-fns 检查日期是否存在于数组中
【发布时间】:2018-01-04 18:05:37
【问题描述】:

我正在使用 date-fns,我可以使用 isMonday(day) 之类的助手,如果当天是星期一,则返回 true,或者使用 isWithinRange(start, end) 检查日期是否在某个范围内,但是,如果日期在日期数组中,有没有办法返回 true?

【问题讨论】:

  • 你说的是 js Date 对象还是……自定义?
  • JS 日期对象,可以是 ISO 或 UTC

标签: javascript


【解决方案1】:

为了简单,只需使用Array prototype.some

 const dateInArray = (date, array) => array.some(d => +d === +date);

【讨论】:

    猜你喜欢
    • 2013-06-08
    • 2021-01-23
    • 2019-03-01
    • 1970-01-01
    • 2019-08-28
    • 2012-02-24
    • 1970-01-01
    • 2021-11-14
    • 1970-01-01
    相关资源
    最近更新 更多