For this, you should use generators.
function generate_flavors* () {
yield "Butter Cream";
yield "Chocolate";
yield "Vanilla";
yield "Red Velvet";
}
Now you can create your array in any of several ways:
console.log(Array.from(generate_flavors()))
console.log(...generate_flavors())
console.log([for (flavor of generate_flavors()) flavor])
Hope that helps.
0
solved Create an Array and Populate it with values in JS [closed]