| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Errors/Array_sort_argument | [Back] [Original] |
Get to know MDN better
Esta pgina foi traduzida do ingls pela comunidade. Saiba mais e junte-se comunidade MDN Web Docs.
A exceo JavaScript "invalid Array.prototype.sort argument" ocorre quando o argumento de Array.prototype.sort() no undefined ou uma funo que compara os seus operandos.
TypeError: The comparison function must be either a function or undefined (V8-based) TypeError: invalid Array.prototype.sort argument (Firefox) TypeError: Array.prototype.sort requires the comparator argument to be a function or undefined (Safari)
TypeError
Espera-se que o argumento de Array.prototype.sort() seja undefined ou uma funo que compare os seus operandos.
[1, 3, 2].sort(5); // TypeError
const cmp = { asc: (x, y) => x >= y, dsc: (x, y) => x <= y };
[1, 3, 2].sort(cmp[this.key] || "asc"); // TypeError
[1, 3, 2].sort(); // [1, 2, 3]
const cmp = { asc: (x, y) => x >= y, dsc: (x, y) => x <= y };
[1, 3, 2].sort(cmp[this.key || "asc"]); // [1, 2, 3]
This page was last modified on 10 de jan. de 2024 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |