如何使用Javascript获得多个对象数组的每个组合

如何使用Javascript获得多个对象数组的每个组合,javascript,arrays,Javascript,Arrays,我试图获得两个对象数组的所有组合的列表 我有两个json文件: 果实 [ { "food": "Apple", "calories": 100 } ], [ { "food": "Orange", "calories": 150 } ] 肉 我想输出数组中所有对象的组合: 苹果100 鸡175 苹果100 牛排200 橙色150

我试图获得两个对象数组的所有组合的列表

我有两个json文件:

果实

[
  {
    "food": "Apple",
    "calories": 100
  }
],
[
  {
    "food": "Orange",
    "calories": 150
  }
]

我想输出数组中所有对象的组合:

苹果100 鸡175

苹果100 牛排200

橙色150 鸡175

橙色150 牛排200

我有一个愚蠢的简单for循环:

 for(let i = 0; i < Fruits.length; i++) {
  for(var j = 0; j < Meat.length; j++)
    {
       combos.push(Fruits[i] + Meat[j])
    }
  };
如果我画一张地图,我会更接近它

combos.map(combo=> {console.log(combo)})
得到

但我不知道如何找到这些对象,甚至不知道它们是否定义在那里

谢谢你的阅读

编辑:通过添加更多的索引和括号,我能够得到我所需要的:

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]]);
  }
};
for(设i=0;i

谢谢

你应该这样做:

for(let i = 0; i < Fruits.length; i++) {
  for(var j = 0; j < Meat.length; j++)
    {
       combos.push([Fruits[i], Meat[j]])
    }
  };
for(设i=0;i
你在那里做的是尝试对对象进行数学运算。

常数=[
[{食物:苹果,卡路里:100}],
[{食物:橙色,卡路里:150}]
];
常量肉=[
[{食物:“鸡肉”,卡路里:175}],
[{食物:“牛排”,卡路里:200}]
];
常量组合=[];
水果.forEach(水果=>肉.forEach(肉=>套餐.push([水果,肉]));

forEach(combo=>console.log(JSON.stringify(combo,null))您需要连接对象的属性,而不是对象本身

for(let i = 0; i < Fruits.length; i++) {
  for(var j = 0; j < Meat.length; j++){
       combos.push(Fruits[i][0].food + " " + Fruits[i][0].calories + " " + Meat[j][0].food + " " + Meat[j][0].calories);
  }
};
for(设i=0;i
演示:

常数=[
[
{
“食物”:“苹果”,
“卡路里”:100
}
],
[
{
“食物”:“橙子”,
“卡路里”:150
}
]
];
常量肉=[
[
{
“食物”:“鸡肉”,
“卡路里”:175
}
],
[
{
“食物”:“牛排”,
“卡路里”:200
}
]
];
让combos=[];
for(设i=0;iconsole.log(组合)您可以使用for循环

膳食=[[{“食物”:“苹果”,“卡路里”:100}],{“食物”:“橙色”,“卡路里”:150}]]
水果=[{“食物”:“鸡肉”,“卡路里”:175}],{“食物”:“牛排”,“卡路里”:200}]]
res=[]
for(设i=0;i<0.length;i++){

对于(让j=0;j是否有任何理由将这些对象包装成数组(单个项目)?我将“水果”作为一张纸,将“肉”作为另一张纸放在谷歌文档中,我将其下载为csv并转换为json。这是转换器给我的格式。
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]]);
  }
};
for(let i = 0; i < Fruits.length; i++) {
  for(var j = 0; j < Meat.length; j++)
    {
       combos.push([Fruits[i], Meat[j]])
    }
  };
for(let i = 0; i < Fruits.length; i++) {
  for(var j = 0; j < Meat.length; j++){
       combos.push(Fruits[i][0].food + " " + Fruits[i][0].calories + " " + Meat[j][0].food + " " + Meat[j][0].calories);
  }
};