function sortByKey(arr, sort_key) {
return arr.sort(function(a, b) {
let x = a[sort_key]*1;
let y = b[sort_key]*1;
return ((x<y)?-1:((x>y)?1:0))
});
}
var tmp_arr = [
{
"age":7,
"name":"zhangsan"
},
{
"age":2,
"name":"lisi"
},
{
"age":9,
"name":"王五"
},
]
var result = sortByKey(tmp_arr, 'age');
console.log(result)