{"id":3281,"date":"2011-03-13T23:17:40","date_gmt":"2011-03-13T17:47:40","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=3281"},"modified":"2012-07-23T11:40:28","modified_gmt":"2012-07-23T06:10:28","slug":"sorting-in-javascript","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/sorting-in-javascript\/","title":{"rendered":"Sorting in javascript"},"content":{"rendered":"<p>Recently in my project I needed to sort an object list on the basis of object name. For the same purpose I created the following function<\/p>\n<p>[java]<\/p>\n<p>function sortList(objList) {<br \/>\n objList.sort(sortByName);<br \/>\n}<\/p>\n<p>function sortByName(a, b) {<br \/>\n var x = a.name;<br \/>\n var y = b.name;<br \/>\n return ((x &lt; y) ? -1 : ((x &gt; y) ? 1 : 0));<br \/>\n}<\/p>\n<p>[\/java]<\/p>\n<p>This function sorts an object list on the basis of name of object. Hope it helps<\/p>\n<p>Sachin Anand<\/p>\n<p>sachin[at]intelligrape[dot]com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently in my project I needed to sort an object list on the basis of object name. For the same purpose I created the following function [java] function sortList(objList) { objList.sort(sortByName); } function sortByName(a, b) { var x = a.name; var y = b.name; return ((x &lt; y) ? -1 : ((x &gt; y) ? [&hellip;]<\/p>\n","protected":false},"author":14,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0},"categories":[1],"tags":[854,505],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/3281"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=3281"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/3281\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=3281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=3281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=3281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}