The JavaScript exception "invalid Array.prototype.sort argument" occurs when the argument of
Array.prototype.sort()
isn't either
undefined
or a function which compares its operands.
TypeError: argument is not a function object (Edge) TypeError: invalid Array.prototype.sort argument (Firefox)
The argument of
Array.prototype.sort()
is expected to be either
undefined
or a function which compares its operands.
[1, 3, 2].sort(5); // TypeError
var 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]
var cmp = { asc: (x, y) => x >= y, dsc: (x, y) => x <= y };
[1, 3, 2].sort(cmp[this.key || 'asc']); // [1, 2, 3]