/*获得对象属性的个数*/ Object.prototype.getProperNum = function() { var propNum = 0; for (var i inthis) { ++propNum }; return propNum }; /*给对象添加properNum的属性*/ for (var i = 0; i < objArr.length; i++) { var num = objArr[i].getProperNum() objArr[i]['properNum'] = num }; /*比较函数*/ var compare = function(obj1, obj2) { var val1 = obj1.properNum; var val2 = obj2.properNum; return val1 - val2 //升序 } var objArr2 = objArr.sort(compare) for (var i = 0; i < objArr2.length; i++) { delete objArr2[i].proper }; console.log(objArr2)