VideosMy ProjectsProgramming BlogGallery
  1. Home
  2. Blog
  3. Get the last element of an array in TypeScript
Programming Blog

Atom/RSS Feed

typescript

Get the last element of an array in TypeScript

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];
Join my mailing list