I have a list of objects I wish to sort based on a field attr of type string. I tried using -
attr
-
list.sort(function (a, b) { retur
You should use > or < and == here. So the solution would be:
list.sort(function(item1, item2) { var val1 = item1.attr, val2 = item2.attr; if (val1 == val2) return 0; if (val1 > val2) return 1; if (val1 < val2) return -1; });