Find something from array is a very common pattern in development.
Now we have
Array.prototype.lastIndexOf to find index of some
value in the array.
And we also has
Array.prototype.find to find some element who in the array in customized way.
But There’s not a way to allow us find something
from the end to the start of array in customized way.
.reverse().find() is work. But there’s two issues:
- unnecessary reverse.
Array.prototype.reverseis not immutable.
You have to write the
findRight in your codebase or
As the result the third issue:
- unnecessary spread
So, perhaps we need
And I create a draft proposal https://github.com/Kingwl/proposal-array-find-right.