How to get last element in an array in JavaScript?

To get last element in array in JavaScript, do this: array[array.length - 1].

Here's how you do it:

const array = [ 100, 42, 99 ];
const last = array[array.length - 1];

console.log(last); // 99