2 ms·
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 ne
by franciscop 5y ago
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