Stop using .reverse().find(): meet findLast()

This title could be clearer and more informative.Try out Clickbait Shieldfor free (5 uses left this month).

JavaScript's new Array.prototype.findLast() and findLastIndex() methods provide a cleaner alternative to reversing arrays when searching from the end. These ES2023 features eliminate the need for inefficient .reverse().find() patterns, offering better performance and safer code for common UI scenarios like finding the last unread message, login event, or form validation error.

5m read timeFrom allthingssmitty.com
Post cover image
Table of contents
The problem with reversing arraysfindLast(predicate)findLastIndex(predicate)Solving real problemsPerfect for React UIsCommon pitfalls & best practicesBrowser supportLet’s recap

Sort: