{}const=>[]async()letfn</>var
Development

findLast() and findLastIndex() — a small revolution in arrays

We show on real examples why new array methods replace the old crutches with reverse(). Briefly, clearly and without mutations.

К

Kodik

Author

2 min read

JavaScript can surprise even in 2025. It would seem that we already have everything to work with arrays: map, filter, find, reduce... But recently new methods have appeared — findLast() and findLastIndex(). And this is not just cosmetics, but a real little revolution.

Why do we need new methods?

Until recently, if we needed to find last element of the array, satisfying the condition, had to be bypassed:

  • Flip the array through reverse() and apply find().

  • Or go through the cycle from the end.

The disadvantages are obvious:

  • reverse() mutates the array — dangerous and not obvious.

  • The cycle is cumbersome and not in the spirit of modern JavaScript.

🔥 100,000+ students already with us

Tired of reading theory?
Time to code!

Kodik — an app where you learn to code through practice. AI mentor, interactive lessons, real projects.

🤖 AI 24/7
🎓 Certificates
💰 Free
🚀 Start learning
Joined today

What has changed

Now everything is easier:

  • findLast() searches for the last element that matches the condition.

  • findLastIndex() returns the index of this element.


const users = [
  { name: "Anya", active: false },
  { name: "Boris", active: true },
  { name: "Vika", active: false },
  { name: "Gosha", active: true }
];

console.log(users.findLast(user => user.active));
// { name: "Gosha", active: true }}

console.log(users.findLastIndex(user => user.active));
// 3
    

Why is it better than the old tricks?

  • The code is readable as text - no need to guess the plan.

  • Safety — no array mutations.

  • Speed — the interpreter goes from the end and stops at the first match.

"Before/after": examples

Task

Was (before)

Now

Last active user


const lastActive = users
  .slice()
  .reverse()
  .find(u => u.active);
          

const lastActive = users.findLast(u => u.active);
          

Last error index


const i = logs.length - 1 - logs
  .slice()
  .reverse()
  .findIndex(e => e.level === "error");
          

const i = logs.findLastIndex(e => e.level === "error");
          

Last even element


let last;
for (let i = arr.length - 1; i >= 0; i--) {
  if (arr[i] % 2 === 0) { last = arr[i]; break; }
}
          

const last = arr.findLast(n => n % 2 === 0);
          

Frequently Asked Questions

  • What is returned? findLast() — element or undefined. findLastIndex() — index or -1.

  • About performance: passes the array once from the end, without turning and copying.

  • TypeScript: signatures are similar to find/findIndex, the transition is minimal.

Conclusion

findLast() and findLastIndex() are a practical replacement for crutch patterns with reverse() and manual loops. The code becomes shorter, safer and more obvious.

🙌 We discuss all these features and novelties in our cozy Telegram channel, where we share news from the world of development, analyze new tools and joke about the life of programmers. Join us — it will be interesting!

🎯Stop procrastinating

Liked the article?
Time to practice!

In Kodik, you don't just read — you write code immediately. Theory + practice = real skills.

Instant practice
🧠AI explains code
🏆Certificate

No registration • No card