DEV Community

Nandhakumar
Nandhakumar

Posted on

How to get last element of an array or string using JS ES13 Feature

Javascript ES13 has released in June 2022 and it has pretty cool new features one of them is at() method that can be used with strings and arrays.

So, before ES13 if you want to find the last element of an array or string.

You need to subtract 1 from the length of the array and string and the calculated value will be passed within [] to get the last element like this 👇

Before ES13

But now, after ES13 you can use at() method with negative indexes to get the elements in reverse order of a string or array like this 👇

After ES13

Simple right?

Thanks for reading this article.

If you find this post helpful

Follow me on Twitter and Instagram to show your support

Cheers ✌️

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more