arrow_back Back to Notebook
typescript
typescript
March 22, 2019

Get the last element of an array in TypeScript

There are a few ways you can get the last element of an array in typescript

Given an array

const arr: string[] = ['one','two','three'];

Using Splice

const lastVal = arr.splice(-1)[0];

Using length

const lastVal = arr[arr.length - 1];

Thanks for reading!

John Wiseman

Full-Stack Software Engineer building scalable digital solutions. specializing in modern web technologies and mission-critical systems.

© 2026

Navigation

Start a Conversation

Ready to discuss your next project? Let's build something extraordinary together.

Get in Touch