javascript last x elements of array code example
Example 1: javascript last element of array
arr.slice(-1)[0]
Example 2: javascript last element of array
var last = arr.slice(-1)[0]
Example 3: return last two values of array in javascript
arr.slice(Math.max(arr.length - 5, 1))
Example 4: array cut only last 5 element
arr.slice(Math.max(arr.length - 5, 0))