Array1 = ["banana", "lemon", "meat"];
Array2 = [
{id: 0; name: "BananaSplit"; ingredients: ["banana", "milk", "suggar"]},
{id: 1; name: "LemonJuice"; ingredients: ["lemon", "juice", "suggar"]},
{id: 2; name: "Chicken"; ingredients: ["meat", "salt", "checkup"]},
{id: 3; name: "Popcorn"; ingredients: ["corn", "salt"]}
]
Array3是Array2中的成分,我正在尝试检查Array1是否与Array2中的任何成分匹配,然后输出数据。
如果找到“香蕉”,则输出:{id:0;名称:“ BananaSplit”;成分:[“香蕉”,“牛奶”,“建议”]}
我尝试了很多版本,但是在此停止:
let restul = (array2.ingredients).filter(value => -1 !== array1.indexOf(value))
console.log(restul);
我得到的数组包含常见成分的结果,但是没有什么配方。