如何从一天的整数值数组中过滤项目,其中一天的整数值必须与第二个事件项目数组中的任何时间戳匹配?

How to filter items from an array of day values where a day's integer value has to match any timestamp from a second array of event items?

在 JSX 中,我通过我在一个月内计算的天数进行映射:

  {range(daysInMonth).map((i) => (
          <div
            className="day-cell day-cell--in-month"
            key={i}
          >
            {i + 1}
          </div>
        ))}

然后我有一系列事件来自 api:

const events = [
{
date: timestamp,
description: "Meeting with friends"
}
//More events//
]

如何映射事件数组并将事件时间戳与正在映射的 daysInMonth 日期的当前时间戳相匹配,然后显示事件描述?

以防上述评论的假设...

"the daysInMonth is just a number, for example for Feb it would be 28." ... thus, one can assume the timestamp/date value of an events item is an integer as well?

... 适用,可以实现前面的 filter task in collaboration with some.

const events = [{
  date: timestamp,
  description: "Meeting with friends"
}/*, { More events }*/];


{
  range(
    
    daysInMonth
    
  ).filter(dayValue =>
    
    events.some(({ date }) => date === dayValue)
    
  ).map(dayValue => (
    <div
      className="day-cell day-cell--in-month"
      key={dayValue}
    >
      {dayValue + 1}
    </div>
  ))
}

编辑

"... thus, one can assume the timestamp/date value of an events item is an integer as well?" – Peter Seliger

"... it's a timestamp from a MySQL database." – adherb

"... then within the already provided filter code of my answer one has to get the day from each events item's date value in order to make it comparable to the integer value of each daysInMonth item." – Peter Seliger

const events = [{
  date: timestamp,
  description: "Meeting with friends"
}/*, { More events }*/];


{
  range(

    daysInMonth

  ).filter(dayValue =>
    events.some(({ date }) =>
      new Date(date).getDay() === dayValue
    )
  ).map(dayValue => (
    <div
      className="day-cell day-cell--in-month"
      key={dayValue}
    >
      {dayValue + 1}
    </div>
  ))
}