Issue
Is there a notation to access the last element of an array in TypeScript? In Ruby I can say: array[-1]
. Is there something similar?
Solution
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"];
alert(items[items.length-1])
Here is a working sample.
Answered By - Shyju
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.