jquery - JSON object sort in Javascript -


i have json object jobj=json.parse(jsnstr) array returned json.parse , wish sort name. have used

jobj=$(jobj).sort(sortfunction);  function sortfunction(a,b){        return a.name.tolowercase() > b.name.tolowercase() ? 1 : -1;    };   

but didnt work out instead getting undefined obj help?

you can't sort hash; must array. can setup reference of each a.name value array , sort array custom function have there.

json = json.parse(...); var refs = []; for(var in json) {   var name = i.name;   refs.push({     name : name.tolowercase(),     object :   }); }  var sorted = refs.sort(function(a,b) {   return a.name > b.name; }); 

now in refs array sorted , can access each object individually sorted[index].object.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -