How do I give a property name that combines a string and integer?
I currently have a for loop that iterates through data and adds it to an object. I am creating the properties and values in each iteration. For example
for(let i = 0; i < 24; i++) {
myObject.hour + i = {
temp: data.hour[i].temp
}
}
I have tried creating a variable such as
var hour = "hour" + i;
but that does not work because it doesn’t recognize me using the variable rather just the string “hour” as the property.
I was wondering if there is a simple solution. I currently have an array which contains each property name I want and just access that array in each iteration to assign the name.