[Solved] array cross-over loop in javascript
This is a functional ES6 approach. let variants = [{ variantName: “Size”, variantItems: [ “XL”, “MD”, “SM” ] }, { variantName: “Color”, variantItems: [ “Red”, “Blue” ] }]; let crossJoined = new Array(variants.reduce((product, variant) => (product * variant.variantItems.length), 1)) .fill(0) .reduce(crossJoin => { crossJoin.data.push(crossJoin.currentIndexes.map((itemIndex, variantIndex) => `${variants[variantIndex].variantName}: ${variants[variantIndex].variantItems[itemIndex]}`).join(“, “)); let incrementableIndex = variants.length – crossJoin.currentIndexes … Read more