Indexing front and back of an array The .at function allows you to index an array from the beginning and the end with positive and negative numbers.

PHOTO EMBED

Wed Feb 22 2023 09:04:31 GMT+0000 (Coordinated Universal Time)

Saved by @EMR4HKLMN

const arr = [1, 2, 3, 4, 5];

arr.at(0) // 1
arr.at(1) // 2
arr.at(-1) // 5
arr.at(-2) // 4
content_copyCOPY

https://dev.to/ironcladdev/15-killer-js-techniques-youve-probably-never-heard-of-1lgp