Thursday, February 5, 2026
HomeLanguagesJavascriptJavaScript TypeError – Invalid Array.prototype.sort argument

JavaScript TypeError – Invalid Array.prototype.sort argument

This JavaScript exception invalid Array.prototype.sort argument occurs if the parameter of Array.prototype.sort() is not from either undefined or a function which sorts accordingly.

Message:

TypeError: argument is not a function object (Edge)
TypeError: invalid Array.prototype.sort argument (Firefox)

Error Type:

TypeError

Cause of the Error: The argument is passed to the sort() method should be either undefined or a function which compares its operands.

Example 1: In this example, argument passed to sort() method is not expected, So the error has occurred.

Javascript




[2, 5, 6, 1, 3].sort(3); // error here


Output:

TypeError: argument is not a function object

Example 2: In this example, argument passed to sort() method is not expected, So the error has occurred.

Javascript




let compareFun = {
    Asc: (a, b) => a >= b,
    Dsc: (a, b) => a <= b
};
 
// TypeError
[1, 2, 3, 6, 5, 8].sort(
    compareFun[this.key] || 'Asc');


Output:

TypeError: argument is not a function object
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32489 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6861 POSTS0 COMMENTS
Nicole Veronica
11983 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12071 POSTS0 COMMENTS
Shaida Kate Naidoo
6994 POSTS0 COMMENTS
Ted Musemwa
7234 POSTS0 COMMENTS
Thapelo Manthata
6946 POSTS0 COMMENTS
Umr Jansen
6928 POSTS0 COMMENTS