I'm struggling with some algorithm with javascript. I'm using Vue as framework and state managament. I have an object that needs to be 'calculated' as variants.
For example, I have 3 objects and in those objects some values as array, like so:
"attributes":[
{
"title":{
"text":"Size",
"value":"1"
},
"values":[
"M",
"L",
"X"
]
},
{
"title":{
"text":"Color",
"value":"2"
},
"values":[
"Red",
"Green",
"Black"
]
},
{
"title":{
"text":"Material"
},
"values":[
"Cotton",
]
}
]
So my state for this is obviously attributes. So what I really need to do is to foreach attribute values and create variant for every possible combination, and console.log them. Like so:
M/Red/Cotton, L/Red/Cotton, X/Red/Cotton, M/Green/Cotton, L/Green/Cotton, X/Green/Cotton, M/Black/Cotton, L/Black/Cotton, X/Black/Cotton
So I started function that will only foreach attributes, so I need to foreach values and make that codes (up) for them, but no idea how to proceed. So it looks like:
addVariant: function (text) {
this.attributes.forEach(element => console.log(element));
},