+ 2
How do I target and update computed property names?
<script type="text/javascript"> //Please, how do i target and update computed property names? let fName="First Name"; let sName="Last Name"; let priv={ [fName]: "Lorri", [sName]: "Flinn", username: "@lorri" age: 25, } //I can target and update normal porperty names like username and age. priv.username="@lorri0"; priv.age="26"; //But how do I target and update [fName] and [sName]? //Thank you as you reply... </script> https://code.sololearn.com/WvikslXU89SW/#html
3 ответов
+ 3
Use bracket notation:
priv[fname] = "Tobi";
https://www.sololearn.com/learn/JavaScript/1151/
+ 1
Thanks... It worked...
+ 1
Firs of all you forgot a comma in the object priv after username: "@lorri". After setting of that can you try above mentioned recomendations.