Homelab, Linux, JS & ABAP (~˘▾˘)~
 

[JavaScript] Get the Last Item in an Array

1
2
3
4
5
6
7
const animals = [‘cat’, ‘dog’, ‘horse’]
 
// before
const lastItem = animals[animals.length - 1]
 
// ES2022
const lastItem = animals.at(-1)

Leave a Reply

Your email address will not be published. Required fields are marked *