how to get last element in array java script code example Example: javascript get last element in an array var last = arr.slice(-1)[0]