BUG?
I was building a library for handling Arrays and I came across the following situation: When adding a value to a negative index within my Array, this index does not appear when using some methods:
Example:
var array = new Array("Maria", "João", "Carlos");
array[-3] = "Bernardo";
console.log(array[-3]); //Bernardo
console.log(array.length); //3
console.log(JSON.stringify(array)); //"["Maria", "João", "Carlos"]"
Note that the quantity continues to be 3 when using length
and the JSON.stringify
method shows only the 3 originals, however, when displaying the array[-3]
the name comes correctly.
Question:
The correct one would not appear length = 4
and appear in method JSON.stringify
? Why does this occur? Is it some kind of language that allows me to add a value to a negative index?