我有這樣更改對象的屬性基於可變
{"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