Alright, I know that there are a few posts about getting the product of an unknown amount arrays with unknown amount of elements –
JavaScript – Generating combinations from n arrays with m elements
Cartesian array based on array of objects in Javascript
To name a few – However, I have a need for a slight twist –
What I would like is a function that can output an Array of serialized objects instead of an Array of Arrays..
for example, if the input of the function were –
scenarioBuilder({ENV: ["QA","UAT"], HOST: ["APP1", "APP2", "APP3"], API: ["Example1", "Example2"]})
The output would be an array of serialized objects like this –
[{ENV: "QA", HOST: "APP1", API: "Example1"},
{ENV: "UAT", HOST: "APP1", API: "Example1"},
{ENV: "QA", HOST: "APP2", API: "Example1"},
{ENV: "UAT", HOST: "APP2", API: "Example1"},
{ENV: "QA", HOST: "APP3", API: "Example1"},
{ENV: "UAT", HOST: "APP3", API: "Example1"}]
etc. etc. etc.
Essentially taking the Array of ENV, HOSTS, AND API’s – and making a serialized scenario builder.
I’ve tried a few cracks at adapting a few of the methods from the above links, but I have had no luck.
Can anyone take a shot at it?
Thank you as always.