Reputation: 1043
I am looking for the most efficient way to write this ternary.
id === this.mygroup ? this.mygroup = '' : this.mygroup = id;
This is in a vuejs method but I suppose it does not matter.
Should I copy to a local var so it does not read it multiple times?
let activeGroup = this.mygroup
id === activeGroup ? activeGroup = '' : activeGroup = id;
Anything else?
Upvotes: 0
Views: 113
Reputation: 4278
this.mygroup = id === this.mygroup ? '' : id;
You assign this.mygroup
to either ''
or id
, which is what you want
Upvotes: 3