Get to know MDN better
The JavaScript exception "Invalid array length" occurs when specifying an array length that is either negative, a floating number or exceeds the maximum supported by the platform (i.e., when creating an Array or ArrayBuffer, or when setting the length property).
The maximum allowed array length depends on the platform, browser and browser version. For Array the maximum length is 232-1. For ArrayBuffer the maximum is 231-1 (2GiB-1) on 32-bit systems. From Firefox version 89 the maximum value of ArrayBuffer is 233 (8GiB) on 64-bit systems.
Note: Array and ArrayBuffer are independent data structures (the implementation of one does not affect the other).
The error might appear when attempting to produce an Array or ArrayBuffer with an invalid length, which includes:
If you are creating an Array using the constructor, you probably want to use the literal notation instead, as the first argument is interpreted as the length of the Array. Otherwise, you might want to clamp the length before setting the length property, or using it as argument of the constructor.
This page was last modified on Jul 8, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.