+ 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

28th May 2020, 5:10 PM
Fin Finale
3 Réponses
+ 3
Use bracket notation: priv[fname] = "Tobi"; https://www.sololearn.com/learn/JavaScript/1151/
28th May 2020, 5:20 PM
Kevin ★
+ 1
Thanks... It worked...
28th May 2020, 5:27 PM
Fin Finale
+ 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.
28th May 2020, 6:06 PM
JaScript
JaScript - avatar