对象展开后 为什么顺序不变啊
var allobj = document.getElementsByTagName('*')
var obj = {},arr=[];
for (var i = 0; i < allobj.length; i++) {
let eleName=allobj[i].tagName.toLowerCase();
obj[eleName]!=undefined?obj[eleName]++:obj[eleName]=1;
}
console.log(obj);
console.log(Object.entries(obj));
let sort = Object.entries(obj).sort((a,b) => b[1] - a[1])
let sortobj = {}
for (var i = 0; i < sort.length; i++) {
sortobj[sort[i][0]] = sort[i][1]
}
对象 key 不具有顺序性,迭代的顺序是依赖于浏览器实现,不具有通用型