for example: I define three variables: data1,data2,data3
and then I want to assign one of them according to the parameter in a function, for example, when the parameter value is 1, assign a value to data1, and a parameter 2, assign a value to data2. This kind, because there may be many kinds of assignment schemes, I think the following kind of if judgment is a little inappropriate, and I did not think of a better method. Please give me some advice from the kind-hearted people who have good methods. Thank you
function Test(param) {
if(param===1){
this.data1 = ...
} else if(param===2){
this.data2 = ...
} else{
this.data3 = ...
}
}
want to achieve an effect similar to the above, but do not use the if.else judgment method
add: I may not be very clear. What I mean is that there may be a lot of parameters and there will be many variables. Is there any way to achieve results like this
?function Test(param) {
this.data+param = ... //
}