I want loop through 1 to 21 and then use this loop numbers for getting an Array of Strings ['e1.wkh',...'e21.wkh']. But right now the only value I got is ['e21.wkh'].
function calculateStats() {
var obj = {}
var deviceId = "34534";
for (var i = 1; i <= 21; i++) {
var loo = i.toString();
console.log(loo);
obj[deviceId] = ['e' + loo + '.kwh'];
console.log(obj[deviceId]);
}
}
deviceIdas the element name here:obj[deviceId] = ['e' + loo + '.kwh'];So you always overwrite the last value ofobj[deviceId]How should the elements be named instead?