Join the Mozilla’s Test Days event from Dec 2–8 to test the new Firefox address bar on Firefox Beta 134 and get a chance to win Mozilla swag vouchers! 🎁

본 사이트는 여러분의 사용자 경험을 개선하기 위해 유지 보수를 진행하는 동안 기능이 제한됩니다. 도움말로 문제가 해결되지 않고 질문을 하고 싶다면 Twitter의 @FirefoxSupport 및 Reddit의 /r/firefox 채널을 활용하세요.

Mozilla 도움말 검색

고객 지원 사기를 피하세요. 저희는 여러분께 절대로 전화를 걸거나 문자를 보내거나 개인 정보를 공유하도록 요청하지 않습니다. "악용 사례 신고"옵션을 사용하여 의심스러운 활동을 신고해 주세요.

자세히 살펴보기

Array.length remains the same even though array has element index greater than length set: Bug or feature?

more options

I don't really know if this is a bug, or a feature of Firefox's JavaScript core engine. Say I have an array:

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[502039410402] = 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.

Thanks!

I don't really know if this is a bug, or a feature of Firefox's JavaScript core engine. Say I have an array: 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[502039410402] = 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. Thanks!
첨부된 스크린샷

모든 댓글 (2)

more options

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 ?

more options

Oh no, array.length isn't read-only? Why, JavaScript, why?! But setting that aside...

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:

I've read many times that everything in JavaScript is an object, so perhaps that's why the limbo elements can exist.