Created
September 25, 2019 13:55
-
-
Save qwersk/f7f659ad94c0cb61d8c9c2614ec7350f to your computer and use it in GitHub Desktop.
Sort object array #js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myFunction(arr) { | |
arr.sort(function(a, b){ | |
var x = a.type.toLowerCase(); | |
var y = b.type.toLowerCase(); | |
if (x < y) {return -1;} | |
if (x > y) {return 1;} | |
return 0; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment