0

There is 1 object in array, which is:

0: {From: Wed Nov 08 2017 07:50:00}

and with this function using lodash I want to find if there is an object equel to date i am looking for, rounded to 10 minutes:

let find = _.findIndex(myArray, e => e.From == new Date(Math.floor(newDate.getTime() / 600000) * 600000));

The newDate date object has a value of Wed Nov 08 2017 07:55:00 and the expected outcome is index 0, instead it returns -1 which means nothing was found.

  • In JS object references are only equal if they point to exactly the same object. – zerkms Nov 08 '17 at 08:42
  • it is a date object –  Nov 08 '17 at 08:43
  • i suggest converting them to timestamps for the comparison. Another thing, "rounding" the date to 10min (floored actually) would only work if the date coming from the array is a "multiple" of 10 minutes too. I would personnally compare timestamp to an interval with `<` and `>` just in case.. – Kaddath Nov 08 '17 at 09:03
  • i know, they are a multiple of 10 minutes, i will now compare their getTime() values, thanks for advices –  Nov 08 '17 at 09:22

0 Answers0