how to get last element in js code example
Example 1: javascipt get last element of array
const arr = [1,2,3] ;
console.log(arr[arr.length - 1]);
Example 2: how to get last item in array javascript
let nums = [1,2,3,4,5];
let lastOne = nums.pop();
// -> lastOne = 5
// -> nums = [1,2,3,4];