change property name

后端 未结 4 1365
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 07:44

I have a JavaScript object as follows:

var a = { Prop1: \'test\', Prop2: \'test2\' }

How would I change the \"property name\" of Prop1 to P

4条回答
  •  野性不改
    2020-11-28 08:42

    Adding to the object rest spread solution

    const { Prop1: Prop3, ...otherProps } = a;
    const newObj = { Prop3, ...otherProps };
    

提交回复
热议问题