Comment

Comment by jankovicsandras

" Negative indexing (.at(-1)): When indexing an array or a string, at can be used to index from the end. It’s equivalent to arr[arr.length - 1) " sic arr[arr.length-1)

This is wrong. Array.at can get, but not set the value. So they're not equivalent.

console.log( arr[arr.length-1] ); // works

arr[arr.length-1] = 1; // works

console.log( arr.at(-1) ); // works

arr.at(-1) = 1; // ReferenceError: Invalid left-hand side in assignment

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton