根據(jù)需求蚊丐,需要把對(duì)象里面的key為has的屬性展示的時(shí)候放到第一個(gè)展示
把對(duì)象轉(zhuǎn)換成數(shù)組后飘蚯,has放到數(shù)組的第一個(gè)位置馍迄,如下:
results = [
"hasin":{id:"1603"},
"h9sin":{id:"1702"},
"abcd":{id:"1502"}
];
//數(shù)組轉(zhuǎn)對(duì)象
var attachmentsObj = {}
results.forEach(item=>{
attachmentsObj[Object.keys(item)[0]] = Object.values(item)[0];
});
//轉(zhuǎn)換為對(duì)象后,順序改變了局骤,如下:原來(lái)瀏覽器會(huì)根據(jù)對(duì)象的key值自動(dòng)排序攀圈,Chrome,edge都會(huì)排序
Obj = {
{
"abcd":{id:"1502"}峦甩,
"h9sin":{id:"1702"},
"hasin":{id:"1603"},
}
}赘来;
//例子:
var objs = {
"hasin":{id:"1603"},
"h9sin":{id:"1702"},
"abcd":{id:"1502"}
};
console.log(objs);
//輸出結(jié)果
{
"abcd":{id:"1502"},
"h9sin":{id:"1702"},
"hasin":{id:"1603"},
}