I am trying to create an array of objects that will be populated by random properties.
I want the objects all to look like this
{ systemStar: "something random", planets: ["random1", "random2", etc]}
Currently I have the following code
const letThereBeLight = () => {
let universe = []
const starNumber = 5;
let randomNumberOfPlanets = Math.floor(Math.random() * 6);
for (let i = 0; i < starNumber; i++) {
universe.push({
systemStar: starList[Math.floor(Math.random() * lengthOfStarList)],
systemPlanets: [planetList[Math.floor(Math.random() * lengthOfPlanetList)]]
})
}
console.log(universe)
}
This does a great job in creating the objects I want with the following format, however the systemPlanets
is only one, instead of a random number. I have tried to do a double for loop but the syntax was eluding me.
How can I get an array of random strings inside of my for loop?
Added variables for clarity
let starList = [
"Red-Giant",
"Red-Supergiant",
"Blue-Giant",
"White-Dwarf",
"Yellow-Dwarf",
"Red-Dwarf",
"Brown-Dwarf",
];
let planetList = [
"Rocky",
"Temperate",
"Ocean",
"Frozen",
"Lava",
"Gas"
];