sort json object by key value javascript
var json = [{
"name": "user1",
"id": 3
}, {
"name": "user2",
"id": 6
}, {
"name": "user3",
"id": 1
}];
// Asc. order
json.sort(function(a, b){
return a.id - b.id;
});
// desc order
json.sort(function(a, b){
return b.id - a.id;
});