How does the `at()` method work for `Array`, `String` and `TypedArray`?
const decepticons = ['Megatron', 'Starscream', 'Blitzwing'];
const lastDecepticon = decepticons.at(-1);
console.log(lastDecepticon); // output: 'Blitzwing'
August 4th, 2022
To get the last item of an array, we had to write array[array.length-1]
. A shorter way is to use the at()
method.