1

I am trying to dynamically add the field name and value in the javascript object using es6 structuring. The problem is its not using the value just the fieldName

updateValue(event){

        let varName = event.target.dataset.field;

        this.realFormData = {...this.realFormData , varName : event.detail.value};
        console.log( this.realFormData); 
    }

Console.log OP: {somefield:"someValue" , varname : "somevalue"}

As you can see, it has used field as varName and not the value of varName

How to bind value of varName instead of its string?

2

1 Answer 1

4

Like this :

this.realFormData = {...this.realFormData , [varName] : event.detail.value};

Not the answer you're looking for? Browse other questions tagged or ask your own question.