Homeyscript variable gets filled with text instead of value

var waterContractPeriodIndex = global.get('waterContractPeriodIndex');
console.log('waterContractPeriodIndex is: '+waterContractPeriodIndex)
var powerContractPeriodIndex = global.get('powerContractPeriodIndex')
console.log('powerContractPeriodIndex is: '+powerContractPeriodIndex)

test = (sort[count] +'ContractPeriodIndex'+'['+(currentMonth -1) +']');
console.log('waterContractPeriodIndex from test is: '+test);
test2 = waterContractPeriodIndex[0];
console.log('waterContractPeriodIndex from test2 is: '+test2)

This is the result:
waterContractPeriodIndex is: 2023,2023,2024,2024,2024,2024,2024,2024,2024,2024,2024,2024

powerContractPeriodIndex is: 2023,2023,2023,2023,2023,2023,2023,2024,2024,2024,2024,2024

waterContractPeriodIndex from test is: waterContractPeriodIndex[0]

waterContractPeriodIndex from test2 is: 2023

In the test i get the name of the variable but not the value, when i enter the name of the variable in test2 it works. How can i make it work in test

console.log('waterContractPeriodIndex from test is: '+eval(test));
1 Like

thx worked at once