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'
Copy

August 4th, 2022

# Negative indexing of arrays

Add to bookmarks

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.

HomeBookmarks