4 ms·
Accessing negative indexes currently returns undefined. This adds support for indexing from the end of an array with negative numbers.
by pininja 5y ago
Accessing negative indexes currently returns undefined. This adds support for indexing from the end of an array with negative numbers.
- franciscop 5y agoThis 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