Skip to content
JS
JavaScript error

TypeError

The JavaScript exception "invalid Array.prototype.sort argument" occurs when the argument of Array.prototype.sort() (and its related methods: Array.prototype.toSorted(), TypedArray.prototype.sort(), TypedArray.prototype.toSorted()) isn't either undefined or a function that compares its operands.

Reference entryJavaScriptFetched
TypeError: The comparison function must be either a function or undefined (V8-based)
As listed by MDN Web Docs
TypeError: invalid Array.prototype.sort argument (Firefox)
As listed by MDN Web Docs
TypeError: non-function passed to Array.prototype.toSorted (Firefox)
As listed by MDN Web Docs
TypeError: invalid %TypedArray%.prototype.sort argument (Firefox)
As listed by MDN Web Docs
TypeError: Array.prototype.sort requires the comparator argument to be a function or undefined (Safari)
As listed by MDN Web Docs
TypeError: Array.prototype.toSorted requires the comparator argument to be a function or undefined (Safari)
As listed by MDN Web Docs
TypeError: TypedArray.prototype.sort requires the comparator argument to be a function or undefined (Safari)
As listed by MDN Web Docs
TypeError: TypedArray.prototype.toSorted requires the comparator argument to be a function or undefined (Safari)
As listed by MDN Web Docs
Category
TypeError
Severity
error
Runtime
both
or press Cmd/Ctrl + Enter. The text is only sent to this site to match it.
Source: MDN Web Docs. Data fetched 2026-09-25T01:48:37.270Z.