Featureresearch
Array exotic objects
Also called Array exotic object, array index, length invariant, ArraySetLength, DefineOwnProperty of arrays, Array.isArray.
ECMA-262 defines an Array as an exotic object whose [[DefineOwnProperty]] keeps length one more than the highest array index. Writing an index grows length, and writing length deletes elements.
- Language
- JavaScript
Synopsis
const a = ["x", "y"];
a[4] = "z";
console.log(a.length);
a.length = 1;
console.log(a, Object.keys(a));
const plain = { length: 0 };
plain[4] = "z";
console.log(plain.length);
console.log(Object.getOwnPropertyDescriptor(a, "length"));
5
[ 'x' ] [ '0' ]
0
{ value: 1, writable: true, enumerable: false, configurable: false }
| Term in ECMA-262 | Meaning |
|---|---|
| Array exotic object | an object whose [[DefineOwnProperty]] is the one of 10.4.2.1 |
| array index | a canonical numeric string for an integer from 0 to 2 to the power 32, minus 2 |
| element | a property whose name is an array index |
length |
a non-configurable data property, always less than 2 to the power 32 |
ArraySetLength |
the steps that run when a program defines length |
IsArray |
the test behind Array.isArray, which also looks through a Proxy |
Semantics
r1. "An Array is an exotic object that gives special treatment to array index property keys".1 What makes it exotic is one internal method: an object is an Array "if its [[DefineOwnProperty]] internal method uses the following implementation, and its other essential internal methods use the definitions found in 10.1."1 Reads, deletes and key listing are ordinary.
r2. "An array index is an integer index n such that CanonicalNumericIndexString(n) returns an integral Number in the inclusive interval from +0๐ฝ to ๐ฝ(232 - 2)", that is, up to 2 to the power 32, minus 2.2 A key such as '01' or '4294967295' is not an array index, so it makes an ordinary property. "A property whose property name is an array index is also called an element."1 Example: keys.
r3. The invariant: "The value of the 'length' property is numerically greater than the name of every own property whose name is an array index".1 The specification keeps it in two directions: "whenever an own property is added whose name is an array index, the value of the 'length' property is changed, if necessary, to be one more than the numeric value of that array index", and when length changes, "every own property whose name is an array index whose value is not smaller than the new length is deleted."1 MDN puts the first direction in engine terms: when the index "is outside the current bounds of the array, the engine will update the array's length property accordingly".3 Example: invariant.
r4. length is a data property, not an accessor. ArrayCreate defines it with [[Writable]]: true, [[Enumerable]]: false and [[Configurable]]: false.1 So Object.getOwnPropertyDescriptor shows a plain value, and delete a.length fails.
r5. A write to length runs ArraySetLength. It converts the value with ToUint32 and with ToNumber, and "If SameValueZero(newLen, numberLen) is false, throw a RangeError exception."1 It deletes elements "in descending numeric index order". If an element cannot be deleted, it stops, sets length to one more than that index and returns false.1 Example: stuck.
r6. If length is not writable, the array cannot grow: "If index โฅ length and lengthDesc.[[Writable]] is false, return false."1 Example: frozen-length.
r7. Array.isArray uses IsArray, which returns true for an Array exotic object and, for a Proxy, "Return ? IsArray(proxyTarget)."4 The test is the internal method, not the prototype (rule r1), so a plain object whose prototype is Array.prototype is not an Array. A subclass instance is one if its constructor calls super: "Subclass constructors that intend to inherit the exotic Array behaviour must include a super call to the Array constructor to initialize subclass instances that are Array exotic objects."5 Example: is-array.
Examples
Which keys are array indexes (rule r2).
const a = [];
a["01"] = "named";
a["4294967295"] = "named too";
a["4294967294"] = "last index";
console.log(a.length, Object.keys(a));
4294967295 [ '4294967294', '01', '4294967295' ]
'4294967294' is the largest array index, so length becomes 2 to the power 32, minus 1. The other two keys are ordinary properties.
An element that cannot be deleted stops the truncation (rule r5). Reflect returns the result instead of throwing.
const a = [1, 2, 3, 4];
Object.defineProperty(a, 1, { configurable: false });
console.log(Reflect.set(a, "length", 0), a.length, a);
false 2 [ 1, 2 ]
ArraySetLength deleted index 3 and index 2, failed at index 1, and set length to 2.
A non-writable length blocks growth (rule r6).
const a = [1, 2];
Object.defineProperty(a, "length", { writable: false });
console.log(Reflect.set(a, 2, 3), Reflect.set(a, 0, 9), a);
try {
a.push(4);
} catch (e) {
console.log(e.name);
}
false true [ 9, 2 ]
TypeError
What Array.isArray accepts (rule r7).
const fake = Object.setPrototypeOf({}, Array.prototype);
fake[3] = "x";
console.log(fake instanceof Array, Array.isArray(fake), fake.length);
const proxy = new Proxy([], {});
class Stack extends Array {
constructor() {
super();
}
}
console.log(Array.isArray(proxy), Array.isArray(new Stack()));
true false 0
true true
fake inherits length from Array.prototype, whose length is 0, and its own index property does not change it. The Stack constructor calls super, so its instance is exotic.
Pitfalls
instanceof Array is not the test
instanceof checks the prototype chain, so fake in the is-array example passes it but has none of the length behaviour. Use Array.isArray, which asks whether the object is exotic (rule r7).
A length that is not a whole number
ArraySetLength throws for a value that does not survive ToUint32 unchanged (rule r5).
This code runs but gives a wrong answer on purpose.
const a = [1, 2, 3];
for (const v of [1.5, -1, 2 ** 32, "2"]) {
try {
a.length = v;
console.log("ok", a.length);
} catch (e) {
console.log(e.name);
}
}
RangeError
RangeError
RangeError
ok 2
The string '2' converts to the same number by both routes, so it is accepted.
Comparison
Python raises an error instead of growing a list: "An IndexError is raised if i is outside the sequence range."6 A Java array has "The public final field length, which contains the number of components of the array", and the field cannot change.7 In Go, "The length is part of the array's type".8 A JavaScript array is the only one of these whose length follows writes to its elements, and that comes from one exotic internal method (rule r1).
References
- ECMAScript 2026 Language Specification (ECMA-262, 17th edition), clause 10, 10.4.2 Array Exotic Objects; 10.4.2.1 [[DefineOwnProperty]]; 10.4.2.2 ArrayCreate; 10.4.2.4 ArraySetLength
- ECMAScript 2026 Language Specification (ECMA-262, 17th edition), clause 6, 6.1.7 The Object Type
- MDN Web Docs, JavaScript Reference, Array, Relationship between length and numerical properties
- ECMAScript 2026 Language Specification (ECMA-262, 17th edition), clause 7, 7.2.2 IsArray
- ECMAScript 2026 Language Specification (ECMA-262, 17th edition), clause 23, 23.1.1 The Array Constructor
- The Python Standard Library, Python 3.14, Built-in Types, Common Sequence Operations, notes
- The Java Language Specification, Java SE 25 Edition, Chapter 10 Arrays, 10.7 Array Members
- The Go Programming Language Specification, Array types
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W3 standard |
|
Tag 966Q11 Edit this page History Report an error Markdown