jquery - how can I make my json array sort function case insensitive? -
jquery - how can I make my json array sort function case insensitive? -
i have next fiddle effort @
taking json array sort array displayname value add sorted array dom list itemsmy issue want able create sort not take consideration case of value when sorting... im noticing considers case , puts uppercase values first.
im matter of integrating .tolowercase() somewhere attempts have failed. / how apply .tolowercase() create sort case insensitive?
js fiddle here
function sortresults(prop, asc) { //sort array passed node value... myarray.jsondata = myarray.jsondata.sort(function(a, b) { if (asc) homecoming (a[prop]> b[prop]) ? 1 : ((a[prop] < b[prop]) ? -1 : 0); else homecoming (b[prop] > a[prop]) ? 1 : ((b[prop] < a[prop]) ? -1 : 0); }); showindom(); }
use function tolowercase() , convert string + ""
myarray.jsondata.sort(function(a, b) { var comp = ((a[prop]+"").tolowercase() > (b[prop]+"").tolowercase()) ? 1 : -1 ; homecoming asc ? comp : -comp; });
jquery
Comments
Post a Comment