I'm using Lodash to convert one JSON structure into another. I need to form all combinations of two arrays and marry-up each combination with a data value taken from a third array.
How do I generate all combinations and extract the right data-item for each?
Source JSON structure:
{
"regimes" : [ "AA", "BB" ],
"axes" : [ "Horizontal", "Vertical" ],
"data-items" : [ 1, 2, 3, 4 ]
}
Destination JSON structure:
[
{
"regime" : "AA",
"axis" : "Horizontal",
"data-item" : 1
},
{
"regime" : "AA",
"axis" : "Vertical",
"data-item" : 2
},
{
"regime" : "BB",
"axis" : "Horizontal",
"data-item" : 3
},
{
"regime" : "BB",
"axis" : "Vertical",
"data-item" : 4
}
]