1、对象排序

let arrData={"张三":15,"李四":30,"万系":2,"是三":3};
function ObjectOrder(data){
	let keysSorted = Object.keys(data).sort(function(a,b){return data[b]-data[a]})   //排序健名
	let newD={};
	for(let i=0;i<keysSorted.length;i++){
		newD[keysSorted[i]]=data[keysSorted[i]];
	}		
	return newD;
}
console.log(ObjectOrder(arrData));
返回结果:Object { "李四": 30, "张三": 15, "是三": 3, "万系": 2 }
Logo

前往低代码交流专区

更多推荐