I manage an array of Objects like this
I see that this is the same
But when I try this
Any idea, please?
Thanks
CodePudding user response:
I don't think it has anything to do with TypeScript or the find method.
If I try to print the result of
new Date("2022-10-12T00:00:00") == new Date(2022, 9, 12)
I get false, so it's normal that the find returns undefined.
Maybe you should try to compare stringified Dates (using methods such as toISOString()) instead of Dates.
CodePudding user response:
Try
this.festivos.find(f => new Date(f.fetcha).getTime()==new Date(2022,9,12).getTime())
When you compare two Date objects, you fall victim to object reference equality. You could compare their time component instead as illustrated above.