function that returns last element in array code example
Example 1: javascript last element of array
var last = arr.slice(-1)[0]
Example 2: get last element of array javascript
let colors = ["red", "yellow", "green"];
let lastELement = colors[colors.length - 1]