JSFiddle - React, Tailwind, and code Playground
JavaScript
// I think the combo you're after is known as cartesian product
// Here's a function to do it, from:
// http://stackoverflow.com/questions/12303989/cartesian-product-of-multiple-arrays-in-javascript
// It needs Underscore.js
function cartesianProductOf() {
return _.reduce(arguments, function(a, b) {
return _.flatten(_.map(a, function(x) {
return _.map(b, function(y) {
return x.concat([y]);
});
}), true);
}, [ [] ]);
};
// Here's your object
var obj = {"varA":['best', 'wp', 'theme'],
"varB":['best*S*','wp*s*', 'theme*S*']
}
// Now I extract the arrays from your object
var idx, jdx, keys = Object.keys(obj), arrays = [], result1 = [], result2 = []
for (idx in keys) {
var key = keys[idx]
var arr = obj[key]
arrays.push(arr)
}
// We can calculate the combos of the obj, but this isn't annotated.
result1 = cartesianProductOf.apply(null, arrays)
// Now turn these back into annotated objects.
for (idx in result1) {
var tmp = result1[idx], obj = {}
for (jdx in tmp) {
obj[keys[jdx]] = tmp[jdx]
}
result2.push(obj)
}
// Done!
console.log(result2)