Untitled UI logotext
Solutions
WebsitesEcommerceMobile AppsWeb AppsProduction Support & Maintenance
Our work
Company
About usBlogPodcastContact us
Book a free consultation

Uncaught TypeError: .sort is not a function ?!

Olivia Rhye

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.

Ready to start a project?

Book a free consultation
Untitled UI logotext
Our work
About us
Blog
Careers
Submit a ticket
Agency Partnerships
Contact
© 2024 fjorge. All rights reserved.
Privacy