Why is a Javascript Array index at most 4294967294 but not 4294967295?

后端 未结 3 502
逝去的感伤
逝去的感伤 2020-12-11 01:45

Javascript\'s index is 32 bit, so it seems that the array index should be able to go up to 4294967295 for a total of 4294967296 elements. But in fact the highest index is 4

3条回答
  •  旧时难觅i
    2020-12-11 02:34

    The ECMA-262 specification (section 15.4) says:

    A property name P (in the form of a String value) is an array index if and only if ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal to 232-1.

    The spec also says that the length property of an array is always less than 232. That would seem to exclude 4294967295 as an array index.

提交回复
热议问题