I want to create an array dynamically based on a variable, like this:
var numRequired = 4
The desired array should look like this:
var requiredArray = ["value_1","value_2","value_3","value_4"]
In this case, the last item in the array should match the value of var numRequired.
Here is what I have tried so far:
I attempted to generate the array using a for loop (I am working with Vue JS)
data: () => ({
requiredArray: [],
tempVariable: []
}),
for (var i = 0; i<this.numRequired; ++i) {
this.tempVariable = "value_" + i;
this.requiredArray.push(this.tempVariable);
}
I suspect my implementation may be incorrect. How can I modify it to achieve the desired outcome?