I have created this script due to the need to perform unique combinations when I receive n number of arrays, it works, however when I want to store in a final array it writes something different. Thank you very much for your help and I hope that the script will be useful to those who need it.
let options = {
"A": ["A1", "A2", "A3", "A4"],
"B": ["B1", "B2"],
"C": ["C1", "C2", "C3", "C4", "C5"],
};
let keys = Object.getOwnPropertyNames(options);
let size = keys.length;
let final = [];
function combinate(n, o) {
for (let i = 0; i < options[keys[n]].length; i++) {
if (n === (size - 1)) {
o = {};
}
o[keys[n]] = options[keys[n]][i];
if ((n - 1) >= 0) {
combinate(n - 1, o);
}
if (n === 0) {
console.log(o);
final.push(o);
}
}
}
if (size > 0) combinate(size - 1, {});
console.log("-----------------------------------")
console.log(final);