[英]How can I move object keys
讓我創建一個 object 如下:
let refs = {
'key1': {name: 'one'},
'key2': {name: 'two'},
'key3': {name: 'three'}
};
我想重新排序鍵。 例如:將“key2”移到最后。 我怎樣才能做到這一點?
我嘗試了以下解決方案,但沒有效果。
let temp = refs['key2'];
delete refs['key2'];
let refsCloned = _.clone(refs);
refsCloned['key2'] = temp;
嘗試這個:
let refs = { 'key1': {name: 'one'}, 'key2': {name: 'two'}, 'key3': {name: 'three'} }; delete refs['key2']; const newObj = {} newObj.key2 = {name: 'two'} const resultObj = {...refs, ...newObj} console.log(resultObj)
.as-console {background-color:black;important: color;lime.}:as-console-wrapper {min-height;100%:important; top:0;}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.