我有这样更改对象的属性基于可变
{"first":["first 1"],"second":["second 1","second 2"],"third":["third 1", "third 2"]}
我希望能够改变基于变量值的属性名称的对象。 如果变量是“秒”,它应该改变属性秒到任何我想要的。 我已经试过一些方法...
这
object[theVariable] = "new second";
将属性的值更改为这个
{"first":["first 1"],"second":"new second","third":["third 1", "third 2"]}
这
object.theVariable = "new second";
将创建一个新的像这样的财产
{"first":["first 1"],"second":["second 1","second 2"],"third":["third 1", "third 2"],"theVariable":"new second"}
这些方法都不能更改属性“第二”到“新的第二”时,“第二”被存储在变量“theVariable”
期望的结果:
{"first":["first 1"],"new second":["second 1","second 2"],"third":["third 1", "third 2"]}
这怎么可能做了什么?
@melpomene:好像是OP希望的关键,更换 –
您的代码不你想要什么,我没有看到问题。 –
[change property name](http://stackoverflow.com/questions/8483425/change-property-name) – melpomene