Payload to array in loop

Hello,

I receive that :

    payload[0].TC1_ERROR
    payload[1].TC2_ERROR 
    payload[2].TC3_ERROR
    payload[3].TC4_ERROR
    payload[4].TC5_ERROR
    payload[5].TC6_ERROR

(all payload value are boolean)

I want to create a dynamic array :

var Nombre_de_TC = 6;
    var TC = [];
    
    for (var i = 0; i < Nombre_de_TC; i++) {
      var y = i+1;
      TC[i] = msg.payload[i][`TC{y}_ERROR`];
    }
    
    msg.test0 = TC[0];
    msg.test1 = TC[1];
    msg.test2 = TC[2];
    
    return msg;

But at the end, test0 / test1 and test2 are empty :
ce

You missed a $ out of the template string.

1 Like

Yes, i have change it to :
TC[i] = msg.payload[i][TC${y}_ERROR];

That should be

TC[i] = msg.payload[i][`TC${y}_ERROR`];