Most JavaScript developers access the last element of an array like this:

const arr = [10, 20, 30, 40];

console.log(arr[arr.length - 1]); // 40

Enter fullscreen mode

Exit fullscreen mode