Uncaught TypeError: .sort is not a function ?!

Sarah Berg

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]; });

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

Last updated by on .

What Are Your Thoughts?

Your email address will not be published. Required fields are marked *