0

i want to pass a string to a javascript function and use it as an attribute like this :

function object (){
   this.somevalue = 1;
   this.somevalue2 = 1;
   this.updateAttribute = function(name,value){
      this.{name} = value;
   }
}

can it be done ? Thank You .

Islam ElHakmi
  • 274
  • 2
  • 10

1 Answers1

0

Yes, you can use [] operator bracket notation:

 this[name] = value;