After js variables and strings are concatenated, how can they still be variables?

under the guidance of others, modified the problem, before sent the wrong question and did not express clearly, the code is as follows. The left side of the colon can be written like this [ result$ {I} AV ]. The number is obtained by the index, but the one to the right of the colon does not know how to write it, so it is not a variable after splicing. The one on the left side of the colon is in the data initialization data of the page function, and on the right side of the colon is let result1A = [1Magazine 3], which is written in the onload function. You need to pass the value to the corresponding data in the initialization data data of the page function after calculation, and V (view) is added at the end. At present, I"d like to know how to use traversal to write more concise code, because the right side of the colon is not concatenated.

this.setData({
      labelAV: labelA,
      result1AV: result1A,
      result2AV: result2A,
      result3AV: result3A,
      result4AV: result4A,
      result5AV: result5A,
      result6AV: result6A,
      result7AV: result7A,
      result8AV: result8A,
      result9AV: result9A
    })

for(i=1;i<10;iPP)
  resultA.push(this.data['result'+i+'AV'])

let resultA = Array(10).fill(0).map((_, i) => this.data[`result${i}AV`])

the description of the problem is a little messy. I understand that your question means something like this:
you need to write a piece of code like this:

const codes = [ `labelAV: labelA` ];
for ( let i = 0; i < 10; iPP ) {
    codes.push( `result${i}AV: result${i}A` );
}
eval( `this.setData( { ${codes.join( ',' )} } )` );

but it is recommended not to write code like this and not to define a bunch of variables such as resultxA. You can save them in an array, which will make it easier to handle a lot of

.
Menu