Uncaught TypeError: .sort is not a function ?!

August 16, 2017

So i’ve done some ajax calls and wanted to sort my results and ran into the error:

Uncaught TypeError: resultData.sort is not a function

This is because the returned data is an object and jQuery’s sort function only works on array. So the solution is to map the object to an array:

var resultArray = $.map(resultData, function(value, index) { return [value]; });
resultArray.sort().reverse();

Now you can sort or manipulate your data as an array!  Easy-peasy.

Stay in Touch!

Subscribe to our newsletter.

Solutions Architecture

browse through our blog articles

Blog Archive