Array.length remains the same even though array has element index greater than length set: Bug or feature?
var array = ;
I set the length of the array to a very large number:
array.length = 155555555;
This now turns the variable array into an array with 155555555 blank slots. If I then do:
array = 5; // Notice that 502039410402 > the previously set 155555555 for length
array.length remains at 155555555, but the actual array is appended with a sudden index 502039410402 (i.e., index 155555553, 155555554, and then suddenly index 502039410402; see screenshot), with that element containing 5. Is this a bug, or an intended feature?
I would appreciate it if anyone could let me know.
Tất cả các câu trả lời (2)
The values you use are very large.
Can you replicate this with small values like 50 and 100 and if not, when does it stop working ?
The MDN article says length must be less than 232 (4294967296).
Elements with indexes beyond that size seem to exist in a state of limbo, and don't behave like members of the array in array operations: