<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
var arrObj = [
{ "name": "zhangsan", "age": 18 },
{ "name": "lisi", "age": 10 },
{ "name": "wangwu", "age": 28 }
];
function sortArrObj(arr, key) {
return arr.sort(function(a, b) {
var m = a[key];
var n = b[key];
return ((m<n) ? -1 : ((m>n) ? 1 : 0));
})
}
console.log(sortArrObj(arrObj, "age"));
</script>
</body>
</html>