😸

ES2022で追加された便利そうな機能

2023/01/19に公開

配列の最後を取得できるat()

引数にマイナス値を指定すれば、配列の末尾から参照してくれる

const array = [1,2,3]
console.log(array.at(-1)) // 3

こう書かなくてよくなった

console.log(array.at(array.length - 1)) // 3

https://github.com/tc39/proposal-relative-indexing-method

insight

Discussion