I am seeking to generate a comprehensive list of combinations from two arrays of objects.
The JSON files I have are:
Fruits
[
{
"food": "Apple",
"calories": 100
}
],
[
{
"food": "Orange",
"calories": 150
}
]
Meat
[
{
"food": "Chicken",
"calories": 175
}
],
[
{
"food": "Steak",
"calories": 200
}
]
I want to display all possible combinations of objects in the arrays:
Apple 100 Chicken 175
Apple 100 Steak 200
Orange 150 Chicken 175
Orange 150 Steak 200
Currently, I have a simple for loop that is not giving me the desired output:
for(let i = 0; i < Fruits.length; i++) {
for(var j = 0; j < Meat.length; j++)
{
combos.push(Fruits[i] + Meat[j])
}
};
The result I get is:
[
'[object Object][object Object]',
'[object Object][object Object]',
'[object Object][object Object]',
'[object Object][object Object]'
]
When using map function, I get a bit closer but still unable to access the objects:
combos.map(combo=> {console.log(combo)})
This gives:
[object Object][object Object]
[object Object][object Object]
[object Object][object Object]
[object Object][object Object]
Looking for guidance on how to access these objects or if they are defined there at all.
Thank you for your help!
Update: By adjusting indexes and adding brackets, I was able to achieve my goal with this code:
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]]);
}
};
Thank you!!