pitosalas pitosalas - 5 months ago 166
TypeScript Question

Typescript: Access last element of an array

Is there a notation to access the last element of an array in typescript? In Ruby I can say:

. Is there something similar? Thanks!


You can access the array elements by it's index. The index for the last element in the array will be the length of the array-1 ( as indexes are zero based).

This should work.

var items: String[] = ["tom", "jeff", "sam"];


Here is a working sample.