The title pretty much descripes it. I got an array of days, sorted by the date. So the 1th of the month would be month[0].
When i pick these days in a loop, would it be faster to do this by
month.find(day => day.date === date)
Or
month[date-1]
Thank you for help :)
It does make a difference. When you use a direct index to look up the associated item, the computational complexity is O(1) - the engine just needs to look at the item at that single index and it finds it. But when you use .find, you go through every element of the array and call the callback on each one, only stopping once the found object passes the test.
That said, you'd only notice a difference if you were doing this sort of thing with a huge array and/or in a very tight loop. The difference will be utterly imperceptible most of the time.