function sortByProperty(prop){ return function(a,b){ if(a[prop] > b[prop]) return 1; else if(a[prop] < b[prop]) return -1; return 0; } } items.sort(sortByProperty(“id”)); //sort according to id