0

I am trying to do something like this but it returns -1 all the time even if it should return an index:

let f = this.events.findIndex(e => e.endTime == this.dataService.yearlyTimeSlots[i].From);

Am I doing something wrong?

  • 2
    *Am I doing something wrong?* Yes, you're not providing enough detail. What is the value of `this.events.findIndex`? What value is passed to *e*? – RobG Jun 07 '17 at 09:48
  • 1
    `-1` means it was not found. That means that there is no element in `this.events` whose `endTime` property is equal to `this.dataService.yearlyTimeSlots[i].From`. –  Jun 07 '17 at 09:50
  • events is an array of objects, e.endTime is a date and this.dataService.yearlyTimeSlots[i].From is a date too, the method itself returns -1 all the time –  Jun 07 '17 at 09:53
  • You need to make sure that the dates you are trying to compare are in precisely the same format, such as msec since epoch, or ISO format, etc. This should not be that hard to debug. Stop the debugger at that line, and examine `this.events` and `this.dataService.yearlyTimeSlots[i]`, and make sure that the latter value occurs as the `endTime` property of some element in `this.events`. Just out of curiosity, where is `i` coming from? –  Jun 07 '17 at 09:56
  • it is index of for loop –  Jun 07 '17 at 10:00

0 Answers0