JavaScript's Cleaner Way to Access Array Last Item with .at() Method

Did you know JavaScript has a cleaner way to get the last item of an array? Starting from ES2022, JavaScript introduced the .at() method: It allows negative indexing, so you can access elements from the end of arrays or strings in a much cleaner way. 🔍 Why does this matter? • Improves readability • Reduces manual indexing logic • Eliminates boilerplate • And it’s just… satisfying to write 😄 💡 Pro tip: .at() is supported in all modern browsers and Node.js 16+. If you're supporting older environments, a small polyfill can bridge the gap. 📣 I’ve started using .at() in my codebase, especially in utility functions and data transformations — and it’s made things much easier to reason about. #NodeJS #JavaScript #WebDevelopment #Tech #DesignPatterns #FrontendDevelopment #WebDevelopment #DeveloperLife #nodejs #backend #backenddeveloper #TypeScript #CodingTips #DeveloperBestPractices

  • text
Felipe Castillo

Backend developer | NodeJS | Typescript | Javascript | Express | PostgreSQL

2mo

I think the pop method too but that might mutate it.

To view or add a comment, sign in

Explore content categories