always get last element in array javascript code example
Example 1: javascript last element of array
arr.slice(-1)[0]
Example 2: javascript get the last array element
const myArray = [1, 2, 3]
console.log(myArray.item(-1))
//=> 3
arr.slice(-1)[0]
const myArray = [1, 2, 3]
console.log(myArray.item(-1))
//=> 3