Find a given day within an array of event data objects - Node.js Array

Node.js examples for Array:Search

Description

Find a given day within an array of event data objects

Demo Code

   /*from w ww. j  a va  2 s  .c  o  m*/
/**
 * @description Helper function to find a given day within an array of event
 *   data objects.
 * @param {Date} day: Date for which to find a match.
 * @param {Array of Object} days: Searched within for a matching day.
 * @returns {Object} The matching event data, or null.
*/
findInDays: function (day, days) {
  for (var i = 0; i < days.length; ++i) {
    var ith = new Date(days[i].value.date);
    if (day.getMonth() === ith.getMonth()
    &&  day.getDate() === ith.getDate()) {
      return days[i];
    }
  }
  return null;
}

Related Tutorials