I am trying to get a list of all the combinations of two array of objects.
I have two json files:
Fruits
[
{
"food": "Apple",
"calories": 100
}
],
[
{
"food": "Orange",
"calories": 150
}
]
Meat
[
{
"food": "Chicken",
"calories": 175
}
],
[
{
"food": "Steak",
"calories": 200
}
]
and I want to output all combinations of objects in the arrays:
Apple 100 Chicken 175
Apple 100 Steak 200
Orange 150 Chicken 175
Orange 150 Steak 200
I have a stupid simple for loop:
for(let i = 0; i < Fruits.length; i++) {
for(var j = 0; j < Meat.length; j++)
{
combos.push(Fruits[i] + Meat[j])
}
};
that is ending up giving me:
[
'[object Object][object Object]',
'[object Object][object Object]',
'[object Object][object Object]',
'[object Object][object Object]'
]
If i do a map i get to it a little more
combos.map(combo=> {console.log(combo)})
gets
[object Object][object Object]
[object Object][object Object]
[object Object][object Object]
[object Object][object Object]
But I'm not sure how to get at the objects or even if they are defined there.
Thanks for reading!
Edited: With the addition of some more indexes and brackets I was able to get what I needed with this:
for(let i = 0; i < this.arrBreakfasts.length; i++) {
for(var j = 0; j < this.arrLunches.length; j++){
this.combos.push([this.arrBreakfasts[i][0], this.arrLunches[j][0]]);
}
};
Thanks!!