JSFiddle - React, Tailwind, and code Playground
JavaScript
var obj = {"varA":[1,2,3],
"varB":['good','bad'],
"varC":[0,100],
"varD":['low','med','high']
}
// flatten the object into an array so it's easier to work with
var obj2list = function(obj) {
var list = [];
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
list.push({
name: key,
val: obj[key]
});
}
}
return list;
};
// implement your favorite version of clone...this isn't particular fast
var cloneObj = function(obj) {
return JSON.parse(JSON.stringify(obj));
}
var iterateAndPopulateCombo = function(currentObj, listToIterate, result) {
if (listToIterate.length == 0) {
result.push(currentObj);
} else {
listToIterate[0].val.forEach(function(d) {
console.log(d)
var newObj = cloneObj(currentObj);
newObj[listToIterate[0].name] = d;
iterateAndPopulateCombo(newObj, listToIterate.slice(1), result);
})
}
}
var list = obj2list(obj);
var result = [];
iterateAndPopulateCombo({}, list, result);
console.log(result);