假设:
externalObject = {
UglyKeyOne: 'val1'
UglyKeyTwo: 'val2'
UglyUnusedKey: 'boo'
}
有没有办法在一个班轮中进行以下2行?即创建newObject
,并在一步中使用解构赋值?
{ UglyKeyOne: keyOne, UglyKeyTwo: keyTwo } = externalObject
newObject = { keyOne, keyTwo }
答案 0 :(得分:1)
这有效:
newObject = { keyOne, keyTwo } = { keyOne: externalObject.UglyKeyOne, keyTwo: externalObject.UglyKeyTwo }