DEV Community

Mohsen Fallahnejad
Mohsen Fallahnejad

Posted on

Customize .sort() method in JS

Sort method by default sorts elements alphabetically:
alt text
But you can add a new method which handles Sorting.
for example:
alt text
Now, imagine we want to sort this object that contains models of Ford car :
alt text


  • Sort by cars name:
    alt text
    output:
    alt text


  • Sort by cars price:
    alt text
    output:
    alt text


  • Sort by cars Delivery Date:
    alt text
    output:
    alt text

If you found it useful, you can follow me and also visit my website, because there are more ways to connect with me. I hope this would help you to improve your coding skills. Thank you for your attention.


This article was originally published on The Dev.to on April 19, 2020 and was written by Mohsen Fallahnejad.

Top comments (0)