Hacker News new | ask | show | jobs
by jankovicsandras 1203 days ago
" 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

1 comments

Thanks, I edited it to include this, just to make it clear.