Array.at(idx)
is a method introduced in ES2022
.
Let’s explore the differences between the traditional Array[idx] and Array.at(idx).
Differences
The most significant difference is the support for negative indices.
const arr = [10, 20, 30]
console.log(arr[-1]) // undefined
const arr = [10, 20, 30]
console.log(arr.at(-1)) // 30