| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Errors/Array_sort_argument | [Back] [Original] |
Get to know MDN better
Dieser Inhalt wurde automatisch aus dem Englischen bersetzt, und kann Fehler enthalten. Erfahre mehr ber dieses Experiment.
Der JavaScript-Ausnahmefehler "ungltiges Argument fr Array.prototype.sort" tritt auf, wenn das Argument von Array.prototype.sort() (und seinen verwandten Methoden: Array.prototype.toSorted(), TypedArray.prototype.sort(), TypedArray.prototype.toSorted()) weder undefined noch eine Funktion ist, die ihre Operanden vergleicht.
TypeError: The comparison function must be either a function or undefined (V8-based) TypeError: invalid Array.prototype.sort argument (Firefox) TypeError: non-function passed to Array.prototype.toSorted (Firefox) TypeError: invalid %TypedArray%.prototype.sort argument (Firefox) TypeError: Array.prototype.sort requires the comparator argument to be a function or undefined (Safari) TypeError: Array.prototype.toSorted requires the comparator argument to be a function or undefined (Safari) TypeError: TypedArray.prototype.sort requires the comparator argument to be a function or undefined (Safari) TypeError: TypedArray.prototype.toSorted requires the comparator argument to be a function or undefined (Safari)
TypeError
Das Argument von Array.prototype.sort() (und seinen verwandten Methoden: Array.prototype.toSorted(), TypedArray.prototype.sort(), TypedArray.prototype.toSorted()) sollte entweder undefined oder eine Funktion sein, die ihre Operanden vergleicht.
[1, 3, 2].sort(5); // TypeError
students.toSorted("name"); // TypeError
[1, 3, 2].sort(); // [1, 2, 3]
[1, 3, 2].sort((a, b) => a - b); // [1, 2, 3]
students.toSorted((a, b) => a.name.localeCompare(b.name));
Array.prototype.sort()Array.prototype.toSorted()TypedArray.prototype.sort()TypedArray.prototype.toSorted()Der Bauplan fr ein besseres Internet.
Teile dieses Inhalts sind 19982026 von einzelnen mozilla.org-Mitwirkenden. Inhalte sind verfgbar unter einer Creative-Commons-Lizenz.
| Web Proxy Viewer | New URL | Original Page |