get array with last element javascript code example
Example 1: js array last element get
.slice(-1)[0]
Example 2: how to check the last item in an array javascript
const colors = ['red', 'yellow', 'green', 'blue']
const lastItem = colors[colors.length - 1]
console.log(lastItem)