Re:Stage 3 Proposal: Array.prototype.at
by pininja on Wednesday June 02, 2021 @08:39AM
(#27367980)
Accessing negative indexes currently returns undefined. This adds support for indexing from the end of an array with negative numbers.
[ Parent
| on HN ]
Re:Stage 3 Proposal: Array.prototype.at
by franciscop on Wednesday June 02, 2021 @08:57AM
(#27368143)
This works, but not the way you'd think:
const arr = [];
arr[-1] = 'Hello world';
console.log(arr[-1]);
// Hello world
Instead of using the negative index, it stringifies the "-1" and uses it as the key of an object both when writing and reading. Thus, arr.length still remains 0